目录
转 Map
maven 依赖
转换
转 List
maven依赖
转换
转 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>>() {});
转 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>>>() {});
Cheung Kwok Wing 随笔