java 使用map返回多个对象组装
Object json=JSONObject.fromObject("{}"); List<Object> list = new ArrayList<Object>(); list.add("1"); list.add("2"); list.add("3"); list.add("4"); list.add("5"); list.add("6"); List<Object> result = new ArrayList<Object>(); Map<String, Object> map = new HashMap<String, Object>(); for(Object str :list){ map.put("name", str); map.put("age", str); result.add(map); } JSONArray arr=JSONArray.fromObject(result); if(arr!=null){ json=arr; } System.out.println(arr);
输出值格式为:[{"age":"6","name":"6"},{"age":"6","name":"6"},{"age":"6","name":"6"},{"age":"6","name":"6"},{"age":"6","name":"6"},{"age":"6","name":"6"}]
时间,请带我像一条小溪流般,安静地流淌,汇入爱的海洋。