從後台傳回的json數據為{"cpu":[100],"mem":[10]}{"cpu":[110],"mem":[11]}{"cpu":[120],"mem":[12]}{"cpu":[130],"mem":[13]}。怎麼利用getJSON的方法獲得數據,單個{"cpu":[100],"mem":[10]}這樣的數據可以獲得,但是一組的卻不行。我在百度知道上問過,但是沒人回答http://zhidao.baidu.com/question/392661669009639965.html。菜鳥哈,勞煩各位看看
public static void main(String[] args) {
JSONArray jsret = new JSONArray();
PrintWriter out = response.getWriter();
for (int i = 10; i <= 13; i++) {
JSONArray jsonArray2 = JSONArray.fromObject(i*10);
JSONArray jsonArray3 = JSONArray.fromObject((i));
JSONObject jb = new JSONObject();
jb.put("cpu", jsonArray2);
jb.put("mem", jsonArray3);
jsret.add(jb);
}
out.write(jsret.toString());
out.flush();
}
如果沒問題,記得順手采納一下