net.sf.json.JSONException: 'object' is an array. Use JSONArray instead

list集合转换JSON出错误

意思是:对象是一个数组。

使用jsonarray取代。

解决方法:

将JSONObject替换为JSONArray

代码:

JsonConfig jsonConfig = new JsonConfig();

jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);

JSONArray json = JSONArray.fromObject(newList, jsonConfig);

result = json.toString();


原文地址:https://www.cnblogs.com/gcczhongduan/p/5372420.html