Re: [json-lib-user] Info about a generic method to convert any object to JSON
Brought to you by:
aalmiray
From: Andres A. <aal...@ya...> - 2007-01-31 16:45:22
|
Venkatesh,=0A=0AYou may use the JSONSerializer, which will convert automati= cally Beans, Maps, DynaBeans to JSONObject;=0Aarrays and Collections to JSO= NArray and nulls to JSONNull.=0A=0AIn the case of using a Number or Boolean= as a parameter, it will return an empty JSONObject, because there is no=0A= property name involved, just the value. On the other hand if you call JSONA= rray.fromObject() directly with these values,=0Athe the result will be a JS= ONArray with one element.=0A=0AI hope this helps.=0A=0ACheers,=0AAndres=0A = =0A-------------------------------------------=0Ahttp://jroller.com/page/aa= lmiray=0A--=0AWhat goes up, must come down. Ask any system administrator.= =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 re= cursion.=0A=0A----- Mensaje original ----=0ADe: Venkatesh Babu <venkatbabuk= r...@gm...>=0APara: jso...@li...=0AEnviado: lunes, = 29 de enero, 2007 19:24:42=0AAsunto: [json-lib-user] Info about a generic m= ethod to convert any object to JSON=0A=0AHi All,=0A=0AI have a question rel= ated to json-lib. Request some knowledgeable person to answer the same.=0A= =0ADoes the library have a generic method that returns JSON for any one of = the java object from the list below:=0A=0Alist of types that can be passed:= Map, List, Number, Boolean, String, array.=0A=0AThe reason I'm asking t= his question is - it seems like for maps, arrays and list objects we can us= e JSONObject.fromObject(), but for types like Number, Boolean, String we ha= ve to use =0AJSONUtils.valueToString() . So, I was wondering if I have to w= rite a wrapper function above these two, so that I can get a generic functi= on that has to check if the object passed is Map, List, array or rest and c= all suitable functions.=0A=0A=0AThank you,=0AVenkatesh=0A=0A=0A------------= -------------------------------------------------------------=0ATake Survey= s. Earn Cash. Influence the Future of IT=0AJoin SourceForge.net's Techsay p= anel and you'll get the chance to share your=0Aopinions on IT & business to= pics through brief surveys - and earn cash=0Ahttp://www.techsay.com/default= .php?page=3Djoin.php&p=3Dsourceforge&CID=3DDEVDEV=0A_______________________= ________________________=0Ajson-lib-user mailing list=0Ajson-lib-user@lists= .sourceforge.net=0Ahttps://lists.sourceforge.net/lists/listinfo/json-lib-us= er=0A=0A=0A=0A=0A=0A=0A=0A=09=0A=09=0A=09=09=0A____________________________= _______________________________ =0ADo You Yahoo!? =0ALa mejor conexi=F3n a = Internet y <b >2GB</b> extra a tu correo por $100 al mes. http://net.yahoo.= com.mx =0A |