用 alibaba 的 fastjson 将 list 或 map 转为 json 字符串


用 alibaba 的 fastjson 将 list 或 map 转为 json 字符串。不用 net.sf.json.JSONObject 或者 net.sf.json.JSONArray。

写法:

    com.alibaba
    fastjson
    1.2.31



import com.alibaba.fastjson.JSONObject;

// List 转 json string

String jsonStr = JSONObject.toJSONString( list );

// Map 转 json string

String jsonStr = JSONObject.toJSONString( map );

// 将 json string 转化为 JSONObject

JSONObject obj = JSONObject.parseObject( jsonStr );

相关