Re: [json-lib-user] JSON Lib Issue
Brought to you by:
aalmiray
|
From: Andres A. <aal...@ya...> - 2006-12-08 00:07:36
|
Hi Janardhanan,=0A=0AHere is what's happening:=0AYou are using "Object" as =
a "catch-all" type for your property, when the JSONObject.fromObject() stat=
ic factories get called=0Afrom the JSONSerializer, it inspects the properti=
es of the input object (IssueObject) by type and determines that the proper=
ty=0A'value' must be converted to a JSONObject, following the chain it find=
s out its a String, but because the original command=0Awas to build a JSONO=
bject and your String value does not begin with a "{" and exception is thro=
wn.=0AAn exception should be thrown too if instead of a String you use a Nu=
mber, Array, Collection or Boolean.=0A=0AThe solution would be to inspect t=
he property's value for a more specific type, once the factory method has r=
eached the conclusion=0Athat the type is "Object" and before it calls fromO=
bject() again. AS you may foresee this is not an easy change and will take =
a=0Acouple of days, I'll register this as a Feature Request (as I consider =
that inspection by type is correct), please keep an eye on the=0Aproject's =
tracker to find out when the change is on the cvs.=0A=0ARegards,=0AAndres=
=0A =0A-------------------------------------------=0Ahttp://jroller.com/pag=
e/aalmiray=0A--=0AWhat goes up, must come down. Ask any system administrato=
r.=0AThere are 10 types of people in the world: Those who understand binary=
, and those who don't.=0ATo understand recursion, we must first understand =
recursion.=0A=0A----- Original Message ----=0AFrom: Janardhanan Vembunaraya=
nan <jve...@gm...>=0ATo: jso...@li...=0ASent: =
Wednesday, December 6, 2006 5:29:53 PM=0ASubject: [json-lib-user] JSON Lib =
Issue=0A=0AHi,=0A=0A =0A=0A I am trying to use JSON in our current project=
and when I try to run the following program I am getting the following err=
or given below. The sample code is also given below. When the property is o=
f type Object then I am getting this error. When I change the type from Obj=
ect to String it works fine. But I need to the type be Object for our requi=
rement.=0A=0A=0A =0A=0A=0AException in thread "main" net.sf.json.JSONExcept=
ion: A JSONObject text must begin with '{' at character 1 of json=0A at net=
.sf.json.util.JSONTokener.syntaxError(JSONTokener.java=0A:502)=0A at net.sf=
.json.JSONObject.<init>(JSONObject.java:660)=0A at net.sf.json.JSONObject.<=
init>(JSONObject.java:839)=0A at net.sf.json.JSONObject.fromString(JSONObje=
ct.java:260)=0A at net.sf.json.JSONObject.fromObject=0A(JSONObject.java:239=
)=0A at net.sf.json.JSONObject.setValue(JSONObject.java:533)=0A at net.sf.j=
son.JSONObject.fromBean(JSONObject.java:162)=0A at net.sf.json.JSONObject.f=
romObject(JSONObject.java:246)=0A at net.sf.json.JSONArray.fromObject=0A(JS=
ONArray.java:199)=0A at net.sf.json.JSONSerializer.toJSON(JSONSerializer.ja=
va:63)=0A at com.debug.JSONIssue.constructJSONFromObject(JSONIssue.java:15)=
=0A at com.debug.JSONIssue.main(JSONIssue.java:11)=0A =0A=0A=0A=0A=0Apackag=
e com.debug;=0A=0Aimport net.sf.json.JSON;=0Aimport net.sf.json.JSONSeriali=
zer;=0A=0Apublic class JSONIssue {=0A=0A public static void main(String arg=
s[]) throws Exception{=0A IssueObject o =3D new IssueObject();=0A o.setVa=
lue("json");=0A System.out.println(constructJSONFromObject(o));=0A=0A=0A }=
=0A private static JSON constructJSONFromObject(IssueObject o) throws Excep=
tion {=0A return JSONSerializer.toJSON(o);=0A }=0A=0A}=0A=0A=0Apackage com=
.debug;=0A=0Apublic class IssueObject {=0A private Object value;=0A =0A pub=
lic IssueObject(){=0A }=0A=0A public Object getValue() {=0A return value;=
=0A }=0A =0A public void setValue(Object value) {=0A this.value =3D value;=
=0A }=0A}=0A=0A=0A=0A =0A=0A =0A=0ARegards,=0A=0AJana=0A=0A----------------=
---------------------------------------------------------=0ATake Surveys. E=
arn Cash. Influence the Future of IT=0AJoin SourceForge.net's Techsay panel=
and you'll get the chance to share your=0Aopinions on IT & business topics=
through brief surveys - and earn cash=0Ahttp://www.techsay.com/default.php=
?page=3Djoin.php&p=3Dsourceforge&CID=3DDEVDEV=0A___________________________=
____________________=0Ajson-lib-user mailing lis...@li...=
rceforge.net=0Ahttps://lists.sourceforge.net/lists/listinfo/json-lib-user=
=0A=0A=0A=0A=0A=0A=0A=0A=09=0A=09=0A=09=09=0A______________________________=
_____________________________ =0ADo You Yahoo!? =0ALa mejor conexi=F3n a In=
ternet y <b >2GB</b> extra a tu correo por $100 al mes. http://net.yahoo.co=
m.mx =0A |