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
提交
取消
