JSON 字符串转换 —— Map、List

目录

转 Map

        maven 依赖

        转换

转 List

        maven依赖

        转换


转 Map

JSON格式为  {key:value,key2:value2,......} 

        maven 依赖

        
            com.alibaba
            fastjson
            1.2.28
        

        转换

String str = "{key:value,key2:value2,......}"
JSONObject jsonObject = new JSONObject(str);
String ContentStr = jsonObject.toString();
Map Content = JSONObject.parseObject(ContentStr, new TypeReference>() {});

转 List

JSON格式为  [{key:value,key2:value2,......}] 

        maven依赖

        
            com.fasterxml.jackson.core
            jackson-databind
            2.13.0
        

        转换

ObjectMapper objectMapper = new ObjectMapper();
List> list = objectMapper.readValue(Content, new com.fasterxml.jackson.core.type.TypeReference>>() {});

                                                                Cheung Kwok Wing 随笔 

你可能感兴趣的:(風華絕代,json)