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);
上一篇:【Gym 100803 G】Flipping Parentheses


下一篇:CSS 3D图片翻转 ——3D Flipping Effect