fastjson使用,json ,object,map,list

fastjson使用,json转换

//引入包
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>XXXXXX</version>
</dependency>

1.map转jsonObject,


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;



//map转JSONObject
JSONObject map2Json(Map map){
    JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(map));
    return jsonObject ;
}

2.list转String,

//List转JSON
String list2Json(List list){
    String json = JSON.toJSONString(map);
    return json;
}

posted @ 2021-06-29 16:23  !!!嘻哈!!!  阅读(44)  评论(0编辑  收藏  举报