字符转List<Map>

需要把字符串数据转换为Map结构的数据

字符串

String str = "[[TESTZYY,f41f32dbfe1f4303a3c2528d82423fc1],[2,11c94aa0f7f94ecfa07593e283251aa3]]";

希望转换为List<Map<String, String>>结构

List<Map<String, String>> list;

[{"TESTZYY": "f41f32dbfe1f4303a3c2528d82423fc1"}, {"2": "2,11c94aa0f7f94ecfa07593e283251aa3"}]

list 泛型是Map

哪位大佬知道有没有现成的jdk api

 String strArr = "[{\"0\":\"zhangsan\",\"1\":\"lisi\",\"2\":\"wangwu\",\"3\":\"maliu\"}," +
                "{\"00\":\"zhangsan\",\"11\":\"lisi\",\"22\":\"wangwu\",\"33\":\"maliu\"}]";
    
        List<Map<String,String>> listObjectFir = (List<Map<String,String>>) JSONArray.parse(strArr);
        //利用JSONArray中的parse方法来解析json数组字符串
        for(Map<String,String> mapList : listObjectFir){
            for (Map.Entry entry : mapList.entrySet()){
                System.out.println( entry.getKey()  + "  " +entry.getValue());
            }
        }
1 Like