将map集合中的数据取出来封装成要求的Json格式

it2023-08-20  70

将map集合中的数据取出来封装成要求的Json格式

@Test public void test8() { Map<String,Integer> map = new HashMap<>(); map.put("数据集总数",1); map.put("数据集版本数",2); map.put("数据集已共享",3); map.put("算法总数",4); map.put("算法版本数",5); map.put("算法已共享",6); map.put("模型总数",7); map.put("模型版本数",8); map.put("模型已共享",9); List<Map<String,Map<String,Integer>>> list = new ArrayList<>(); Map<String,Integer> map1 = new LinkedHashMap<>(); map1.put("总数",map.get("数据集总数")); map1.put("版本数",map.get("数据集版本数")); map1.put("已共享",map.get("数据集已共享")); Map<String,Map<String,Integer>> map2 = new HashMap<>(); map2.put("数据集",map1); Map<String,Integer> map3 = new LinkedHashMap<>(); map3.put("总数",map.get("算法总数")); map3.put("版本数",map.get("算法版本数")); map3.put("已共享",map.get("算法已共享")); Map<String,Map<String,Integer>> map4 = new HashMap<>(); map4.put("算法",map3); Map<String,Integer> map5 = new LinkedHashMap<>(); map5.put("总数",map.get("模型总数")); map5.put("版本数",map.get("模型版本数")); map5.put("已共享",map.get("模型已共享")); Map<String,Map<String,Integer>> map6 = new HashMap<>(); map6.put("模型",map5); Collections.addAll(list,map2,map4,map6); String s = JSON.toJSONString(list); System.out.println(s); }
最新回复(0)