上一篇c# 的万能型Json 解析,现在写一篇Java的万能型Json 解析
导入FastJson依赖
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.61</version> </dependency>
使用JSON.parseObject()
Object list = JSON.parseObject(jsonStr, new TypeReference<Object>(){});
比如解析一个User对象
User user = JSON.parseObject(jsonStr, new TypeReference<User>(){});
解析Map,List
Map<String,String> list = JSON.parseObject(jsonStr, new TypeReference<Map<String,String>(){});
List<String> list = JSON.parseObject(jsonStr, new TypeReference<List<String>>(){});