Obect,对象,map,Json互相转换
作者:互联网
加入依赖fastjson
<!-- fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.58</version>
</dependency>
Object
Object转为Json
String s = JSONObject.toJSONString(object);
Object转为对象
TradeGoods tradeGoods = JSONObject.parseObject(JSONObject.toJSONString(object), TradeGoods.class);
Object转map
Map<String,Object> map = JSONObject.parseObject(JSONObject.toJSONString(object), Map.class);
对象
对象转json
String json= JSONObject.toJSONString(tradeGoods1);
对象转Map
Map<String,Object> map = JSONObject.parseObject(JSONObject.toJSONString(tradeGoods), Map.class);
对象转object
Object Object = JSONObject.parseObject(JSONObject.toJSONString(tradeGoods), Object.class);
JSON
json转对象
TradeGoods tradeGoods = JSONObject.parseObject(json, TradeGoods.class);
json转map
Map map = JSONObject.parseObject(json, Map.class);
json转Object
Object object= JSONObject.parseObject(json, Object.class);
标签:Obect,map,Map,JSONObject,Object,json,parseObject,Json,class 来源: https://blog.csdn.net/weixin_42654295/article/details/119011286