Re: [json-lib-user] Converting JSONSerializer.toJSON
Brought to you by:
aalmiray
From: Andres A. <aal...@ya...> - 2008-06-25 19:49:24
|
Hi Haritha, jsonConfig.setRootClass() only makes sense when you are converting from JSON to Java (by calling toBean/toList/toArray/toJava in the proper classes). Please make sure you are testing with the latest stable release (2.2.2), if the problem persists then we have a bug. ------------------------------------------- http://jroller.com/aalmiray http://www.linkedin.com/in/aalmiray -- What goes up, must come down. Ask any system administrator. There are 10 types of people in the world: Those who understand binary, and those who don't. To understand recursion, we must first understand recursion. ----- Original Message ---- From: Haritha Juturu <har...@ya...> To: jso...@li...; aal...@ya... Sent: Wednesday, June 25, 2008 12:33:15 PM Subject: Fw: [json-lib-user] Converting JSONSerializer.toJSON Hi All As an update to my previous query I have even tried LinkedHashMap allPhotos = new LinkedHashMap<String, Object>(); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setRootClass(LinkedHashMap.class); json = JSONObject.fromObject(allPhotos,jsonConfig); json.toString(); but it gives me the same result. Is there a way to get the JSON string in the same order. Haritha ----- Forwarded Message ---- From: Haritha Juturu <har...@ya...> To: jso...@li...; aal...@ya... Sent: Wednesday, June 25, 2008 12:07:19 PM Subject: [json-lib-user] Converting JSONSerializer.toJSON Hi All/Andres I have a LinkedHashMap allPhotos = new LinkedHashMap<String, Object>(); which has objects sorted in order of insertion. What i am trying to do is convert this to a JSON string by using the following code JSONObject json = (JSONObject) JSONSerializer.toJSON( allPhotos ); json.toString(); When i do this the JSON that is created looses the order of the elements in allPhotos. Example I put data in this order allPhotos.put('abc','david'); allPhotos.put('cdg','jason'); allPhotos.put('efg','brian'); But my final json string looks like this {"cdg":"jason","efg":"brian","abc":"david"} Retaining this order is important to our application. Can anyone tell me how i can achieve that? Thanks Haritha |