Re: [json-lib-user] Quick Question on JSON
Brought to you by:
aalmiray
From: Haritha J. <har...@ya...> - 2007-12-11 21:58:08
|
Yes i get this exception on calling JSONObject json =3D json.getJSONObject(= "JSON" );=0A=0AException in thread "main" net.sf.json.JSONException: JSONO= bject["JSON"] is not a JSONObject.=0A at net.sf.json.JSONObject.getJSONO= bject(JSONObject.java:1813)=0A at com.splashnote.web.pages.JavaToJson.ge= tJSON(JavaToJson.java:132)=0AHaritha=0A=0A----- Original Message ----=0AFro= m: Andres Almiray <aal...@ya...>=0ATo: Haritha Juturu <haritha.juturu= @yahoo.com>; jso...@li...=0ASent: Tuesday, December = 11, 2007 1:04:11 PM=0ASubject: Re: [json-lib-user] Quick Question on JSON= =0A=0A=0AHi Haritha,=0A=0AYou are right, if it is a nested JSONObject it sh= ould print it without the surrounding double quotes. As a last resort, can = you call=0A=0AJSONObject jsonObj =3D JSONObject.fromObject( textField, json= Config );=0AJSONObject json =3D json.getJSONObject( "JSON" );=0A=0AIf it re= ally is a JSONObject then no exception should arise. If no exception is thr= own then there may be something going on with the string representation of = a JSONObject when printed.=0A=0AThanks,=0AAndres=0A=0A=0A----- Original Mes= sage ----=0AFrom: Haritha Juturu <har...@ya...>=0ATo:=0A Andres= Almiray <aal...@ya...>; jso...@li...=0ASent: = Tuesday, December 11, 2007 12:59:32 PM=0ASubject: Re: [json-lib-user] Quick= Question on JSON=0A=0A=0AHi Andres=0A=0AThe TextField bean looks like this= =0Apublic class TextField(){ =0A private Long parentId;=0A private Lon= g textFieldId;=0A private String JSON;=0A}=0A=0AAfter executing the code= JSONObject jsonObj =3D JSONObject.fromObject( textField, jsonConfig ); , = i try to print this object 'jsonObj" and it prints the name value pair( of = JSON Property) with quotes=0A=0A{"parentId":678,"textFieldId":111,"JSON":"{= 'sizeWidth':620,'text':'=93[Winning the Nobel Peace Prize]=0A ','positionLe= ft':20,'style':'left:20px;top:100px;width:620px;height:100px;','positionTop= ':100,'name':'','cssClass':'','objectType':'TextObject','sizeHeight':100}"}= =0A=0AIf it was converting this 'JSON' property to JSONObject internally, w= ont it print as=0A=0A"JSON":=0A{"parentId":678,"textFieldId":111,"JSON":{'s= izeWidth':620,'text':'=93[Winning=0Athe Nobel Peace Prize]=0A','positionLef= t':20,'style':'left:20px;top:100px;width:620px;height:100px;','positionTop'= :100,'name':'','cssClass':'','objectType':'TextObject','sizeHeight':100}}= =0Awithout the quotes on the value.=0A=0APlease correct me if i got it wron= g=0A=0AI am using the json-lib-2.1 for jsd 1.5 version.=0AHaritha=0A=0A=0A= =0A----- Original Message ----=0AFrom: Andres Almiray <aal...@ya...>= =0ATo: Haritha Juturu <har...@ya...>; jso...@li...urc= eforge.net=0ASent: Tuesday, December 11, 2007 12:27:12 PM=0ASubject: Re: [j= son-lib-user] Quick Question on JSON=0A=0A=0AHi Haritha,=0A=0AAre you sure = the contents of the named property ('JSON') are not automatically converted= into a JSONObject ? it looks to me like it is a well formed json string, i= f so it should be converted automatically when you call fromObject() at top= level.=0A=0ACan you please tell us which version of Json-lib are you testi= ng with?=0A=0ARegards,=0AAndres=0A=0A----- Original Message ----=0AFrom: Ha= ritha Juturu <har...@ya...>=0ATo: jso...@li...urcefor= ge.net=0ASent: Tuesday, December 11, 2007 12:16:36 PM=0ASubject: [json-lib-= user] Quick Question on JSON=0A=0A=0AHi Everyone=0AI have a line of code=0A= JSONObject jsonObj =3D JSONObject.fromObject( textField, jsonConfig ); =0A= which produces this JSON string=0A=0A{"parentId":678,"textFieldId":111,=0A"= JSON":=0A"{'sizeWidth':620,'text':'=93[Winning the Nobel Peace Prize]','pos= itionLeft':20,'style':'left:20px;top:100px;width:620px;height:100px;','posi= tionTop':100,'name':'','cssClass':'','objectType':'TextObject','sizeHeight'= :100}"=0A}=0A=0Anow if i want the property "json" whose value is a string= =0A =93[Winning the Nobel Peace=0APrize]','positionLeft':20,'style':'left:2= 0px;top:100px;width:620px;height:100px;','positionTop':100,'name':'','cssCl= ass':'','objectType':'TextObject','sizeHeight':100}"=0A=0Ato be converted t= o a json object .... is there any API methods i can use.i am unable to loca= te any.=0A=0Ai.e my output should look like =0A{"parentId":678,"textFieldI= d":111,=0A"JSON": this value is not a string anymore=0A{'sizeWidth':620,'te= xt':'=93[Winning=0Athe Nobel Peace=0APrize]','positionLeft':20,'style':'lef= t:20px;top:100px;width:620px;height:100px;','positionTop':100,'name':'','cs= sClass':'','objectType':'TextObject','sizeHeight':100}=0A}=0A=0AI have a co= nstraint that i need to do this manipulation on the jsonObj .=0A=0AThanks= =0AHaritha=0A=0A=0A=0A=0A=0A=0A Be a better friend, newshound, and =0A= know-it-all with Yahoo! Mobile. Try it now.=0A=0A=0A=0A=0A=0A Be a be= tter friend, newshound, and =0Aknow-it-all with Yahoo! Mobile. Try it now.= =0A=0A=0A=0A=0A=0A Looking for last minute shopping deals? =0AFind th= em fast with Yahoo! Search.=0A=0A=0A=0A=0A=0A=0A=0A=0A Never miss a th= ing. Make Yahoo your homepage.=0A=0A=0A=0A=0A=0A=0A=0A _____________= _______________________________________________________________________=0AB= e a better friend, newshound, and =0Aknow-it-all with Yahoo! Mobile. Try i= t now. http://mobile.yahoo.com/;_ylt=3DAhu06i62sR8HDtDypao8Wcj9tAcJ =0A |