JSON字符串转换——Map、List

JSON字符串转Map,JSON格式为  {key:value,key2:value2,......} 

maven依赖

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.28</version>
        </dependency>
String str = "{key:value,key2:value2,......}"
JSONObject jsonObject = new JSONObject(str);
String ContentStr = jsonObject.toString();
Map<String, Object> Content = JSONObject.parseObject(ContentStr, new TypeReference<Map<String, Object>>() {});

JSON字符串转List,JSON格式为  [{key:value,key2:value2,......}] 

maven依赖

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.13.0</version>
        </dependency>
ObjectMapper objectMapper = new ObjectMapper();
List<Map<String, Object>> list = objectMapper.readValue(Content, new com.fasterxml.jackson.core.type.TypeReference<List<Map<String, Object>>>() {});

 

 

 

 

 

 

 

                Leslie Cheung 随笔

posted @ 2023-07-13 15:35  Leslie_Cheung  阅读(236)  评论(0编辑  收藏  举报