我已經開始使用JSON,我通過AJAX調用從JSP返回JSON。它的工作很好。在JSP中格式JSON字符串
只有我需要改變我返回的JSON字符串的格式。
以下是我的JSP正在返回的字符串。
[{"VV":0,"desc":"XXXXXXX","amount":0,"date":"12/03/2013","watch":""},{"VV":1,"desc":"XXXXXXX","amount":1,"date":"12/03/2013","watch":""}]
以下是我想讓我的JSP返回的字符串。
{"total":"2","rows":[{"VV":0,"desc":"XXXXXXX","amount":0,"date":"12/03/2013","watch":""},{"VV":1,"desc":"XXXXXXX","amount":1,"date":"12/03/2013","watch":""}] }
可以任何人請幫助。
以下代碼我正在使用發送輸出回到前端。
JSONArray arrayObj=new JSONArray();
JSONObject json = new JSONObject();
json.put("VV", i);
json.put("desc", "XXXXXXXXX");
json.put("amount", 1);
json.put("date", "12/03/2013");
json.put("watch", "");
PrintWriter out1 = response.getWriter();
out1.println(arrayObj);