fastjson List转JSONArray以及JSONArray转List

1.fastjson  List转JSONArray
List list = new ArrayList();
JSONArray array= JSONArray.parseArray(JSON.toJSONString(list));

 

2.fastjson  JSONArray转List

JSONArray array = new JSONArray();

List list = JSONObject.parseArray(array.toJSONString(), EventColAttr.class);

 

3.fastjson  字符串转List
String str = "";
List list = JSONObject.parseArray(str,T.class);

 

注意:如果类中有泛型,不可以直接转,需要从json中取出,放入确定的类中,再进行封装;

 

 

 

你可能感兴趣的:(JSONObject)