List转JSONArray和JSONArray转List

1.List转JSONArray

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

2.JSONArray转List

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

3.String转JSONArray

String st = "[{name:Tim,age:25,sex:male},{name:Tom,age:28,sex:male},{name:Lily,age:15,sex:female}]";
JSONArray tableData = JSONArray.parseArray(st);

原文链接:https://blog.csdn.net/weixin_42365088/article/details/99761931

你可能感兴趣的:(jdk,/,线程池/,线程安全)