Quantcast
Channel: JSON order mixed up - Stack Overflow
Viewing all articles
Browse latest Browse all 18

Answer by sang for JSON order mixed up

$
0
0

from lemiorhan examplei can solve with just change some line of lemiorhan's codeuse:

JSONObject json = new JSONObject(obj);

instead of this:

JSONObject json = (JSONObject) obj

so in my test code is :

Map item_sub2 = new LinkedHashMap();item_sub2.put("name", "flare");item_sub2.put("val1", "val1");item_sub2.put("val2", "val2");item_sub2.put("size",102);JSONArray itemarray2 = new JSONArray();itemarray2.add(item_sub2);itemarray2.add(item_sub2);//just for testitemarray2.add(item_sub2);//just for testMap item_sub1 = new LinkedHashMap();item_sub1.put("name", "flare");item_sub1.put("val1", "val1");item_sub1.put("val2", "val2");item_sub1.put("children",itemarray2);JSONArray itemarray = new JSONArray();itemarray.add(item_sub1);itemarray.add(item_sub1);//just for testitemarray.add(item_sub1);//just for testMap item_root = new LinkedHashMap();item_root.put("name", "flare");item_root.put("children",itemarray);JSONObject json = new JSONObject(item_root);System.out.println(json.toJSONString());

Viewing all articles
Browse latest Browse all 18

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>