Tuesday, 15 September 2015

Ordered JSON String in Android


JSON
   
             JSON   object is an unordered set of name/value pairs.So the Android changes the order of JSON ,To keep the values order use the below code


Map obj=new LinkedHashMap();

   obj.put("name","Dhinakaran");

   obj.put("Blog","AndroidDhina");

   obj.put("Number","19");

   obj.put("Job","S/W");

   StringWriter out = new StringWriter();

   JSONValue.writeJSONString(obj, out);

   String jsonText = out.toString();


And Download "json simple 1.1 jar" from this link

And add the jar file to your lib folder

Happy Coding:)