String转list<Map<String,string>> list

String appNames = "[{\"cpuNumber\":4,\"memorySize\":8,\"serverName\":\"ddd\",\"serversNumber\":1},{\"cpuNumber\":4,\"memorySize\":8,\"serverName\":\"aaa\",\"serversNumber\":1},{\"cpuNumber\":2,\"memorySize\":4,\"serverName\":\"bbb\",\"serversNumber\":1}]";
List<Map<String, String>> list = (List<Map<String, String>>) JSONArray.parse(appNames);
        System.out.println(list);
        for(Map<String,String> mapList : list){
            System.out.println(mapList);
            for(Map.Entry entry : mapList.entrySet()){
                System.out.println(entry.getKey());
                System.out.println(entry.getValue());
                if("serverName".equals(entry.getKey())){
                    System.out.println(entry.getValue());
                }
            }
        }

 

posted @ 2021-09-26 14:09  照旧  阅读(475)  评论(0编辑  收藏  举报