如下代码:
@RequestMapping(value = "getCode1.html")
@ResponseBody
public JSONObject getJSON(){
List<Map<Object,Object>> list = new ArrayList<>();
Map<Object,Object> map = new HashMap<>();
JSONObject json=new JSONObject();
map.put("message", "111");
map.put("message2", "222");
map.put("message3", "333");
map.put("message4", "444");
map.put("message5", "555");
map.put("message6", "666");
list.add(map);
json.accumulate("messages", map);
json.accumulate("messages1", 123);
json.accumulate("messages2", 456);
json.accumulate("messages3", 789);
json.accumulate("messages1", map);
return json;
}
则请求之后返回为:
{"messages":{"message4":"444","message3":"333","message6":"666","message5":"555","message":"111","message2":"222"},"messages1":[123,{"message4":"444","message3":"333","message6":"666","message5":"555","message":"111","message2":"222"}],"messages2":456,"messages3":789}