Map中的数据与JSON 互转
将对象转成String类型 存入map
1.使用com.alibaba.fastjson.JSONObject.toJSONString方法 将对象转成String 并放入map中
Map<String, String> orderParam = new HashMap<String, String>(10);
orderParam.put("dealOrderTyxb", JSONObject.toJSONString(dealOrderTyxb));
map中数据转JSON
1.通过map.get方法取出String类型数据,再通过com.alibaba.fastjson.JSONObject.parseObject方法转成对象
String dealOrderTyxbStr = (String)map.get("dealOrderTyxb");
JSONObject dealOrderTyxb = this.toDealOrderTyxb(JSONObject.parseObject(dealOrderTyxbStr));
对应maven jar包
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<!--<version>1.2.61</version>-->
<version>1.2.73</version>
</dependency>