0
我正在嘗試爲jqgrid創建JSON對象。數據被添加但正確但第二條記錄被覆蓋。
ArrayList resList = connect.statement_query(sql, para);
jsonObject = new JSONObject();
jsonObject.put("total", resList.size()/para.length);
jsonObject.put("page", 1);
jsonObject.put("records", resList.size()/para.length);
JSONArray cellArray = new JSONArray();
JSONArray cell = new JSONArray();
JSONObject cellObj = new JSONObject();
for (int i = 0; i < resList.size(); i += para.length) {
cellObj.put("id", resList.get(i));
JSONArray temp=new JSONArray();
temp.add(resList.get(i));
temp.add(resList.get(i + 1));
temp.add(resList.get(i + 2));
temp.add(resList.get(i + 3));
temp.add(resList.get(i + 4));
cell=temp;
cellObj.put("cell", cell);
System.out.println("Cell Obj: "+cellObj.toJSONString());
cellArray.add(cellObj);
System.out.println("Cell Array: "+cellArray.toJSONString());
//cellObj.clear();
temp.clear();
}
System.out.println("Cell Array-Out: "+cellArray);
jsonObject.put("rows", cellArray);
結果出來爲:
Cell Obj: {"id":"1000","cell":["1000","BE6K","vshekhar","2014-06-02","N\/A"]}
Cell Array: [{"id":"1000","cell":["1000","BE6K","vshekhar","2014-06-02","N\/A"]}]
Cell Obj: {"id":"1001","cell":["1001","BOA","maahamad","2013-05-01","N\/A"]}
Cell Array: [{"id":"1001","cell":["1001","BOA","maahamad","2013-05-01","N\/A"]},{"id":"1001","cell":["1001","BOA","maahamad","2013-05-01","N\/A"]}]
Cell Array-Out: [{"id":"1001","cell":[]},{"id":"1001","cell":[]}]
- 爲什麼單元陣列覆蓋掉上第二個記錄?爲什麼它會空出的圈?如何克服它?
這使情況變得更糟。 'Cell Obj:{「id」:「1000」,「cell」:[「1000」,「BE6K」,「vshekhar」,「2014-06-02」,「N \/A」]} Cell Array:[{「id」:「1000」,「cell」:[「1000」,「BE6K」,「vshekhar」,「2014-06-02」,「N \/A」]}] Cell Obj: {「id」:「1001」,「cell」:[「1001」,「BOA」,「maahamad」,「2013-05-01」,「N \/A」]} 單元格數組:[{「id 「:」 1000" , 「細胞」:[]},{ 「ID」: 「1001」, 「細胞」:[ 「1001」, 「BOA」, 「maahamad」, 「2013年5月1日」,「N \「A」]}] Cell Array-Out:[{「id」:「1000」,「cell」:[]},{「id」:「1001」,「cell」:[]}]' – MalTec
請檢查更新後的答案。 – Payal
試過。如果我沒有清除它。它仍然覆蓋。 – MalTec