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 随笔
一生大笑能几回,斗酒相逢需醉倒
本文来自博客园,作者:Leslie_Cheung,转载请注明原文链接:https://www.cnblogs.com/Leslie-Cheung/p/17551085.html