标签:detail hashmap object getjson add color size values ash
/**
* @param array JSON数组
* @param array 需合并后的某个元素名
*/
private static JSONArray mgreArray(JSONArray array, String arrayname) { Map<Integer, JSONObject> map = new HashMap<>(); for (int i = 0; i < array.size(); i++) { JSONObject jsonObject = array.getJSONObject(i); Integer id = jsonObject.getIntValue("id"); //合并的条件值 if (map.containsKey(id)) { JSONObject tmp = map.get(id); JSONArray detailList = tmp.getJSONArray(arrayname); detailList.addAll(jsonObject.getJSONArray(arrayname)); } else { map.put(id, jsonObject); } } JSONArray newArray = new JSONArray(); newArray.addAll(map.values()); return newArray; }
标签:detail hashmap object getjson add color size values ash
原文地址:https://www.cnblogs.com/codechange/p/10255263.html