java 解析json 万能型
作者:互联网
上一篇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>>(){});
标签:jsonStr,java,万能,JSON,parseObject,json,new,解析,TypeReference 来源: https://www.cnblogs.com/yhood/p/11596497.html