1. 程式人生 > >net sf json JSONException 'object' is an array Use JSONArr

net sf json JSONException 'object' is an array Use JSONArr

               

list集合轉換JSON出錯誤

意思是:物件是一個數組。使用jsonarray代替。

解決方法:

將JSONObject替換為JSONArray

程式碼:

JsonConfig jsonConfig = new JsonConfig();

jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);

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

result = json.toString();