JSON秩序混淆我想让我的页面打印出JSONObject按照我想要的顺序。在我的代码中,我输入了以下内容:JSONObject myObject = new JSONObject();myObject.put("userid", "User 1");myObject.put("amount", "24.23");myObject.put("success", "NO");但是,当我看到页面上的显示时,它会给出:JSON格式字符串:[{"success":"NO","userid":"User 1","bid":24.23}我需要它的次序,用户标识,数量,然后成功。已经尝试在代码中重新排序,但没有结果。我也试过.append.这里需要帮助谢谢!
3 回答
猛跑小猪
TA贡献1858条经验 获得超8个赞
JSONObject json = new JSONObject(obj);
JSONObject json = (JSONObject) obj
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());
添加回答
举报
0/150
提交
取消