1,字符串转JSON对象
String result = "{'XXX',[{'XXX','XXX'},{'XXX','XXX'}]}";
JSONObject jsonObject = JSON.parseObject(result);
2,字符串转JSON数组对象
JSONArray jsonArray = JSONArray.parseArray(map.get("resultList").toString());
3,遍历JSON数组
JSONArray whiteBoardBookList = JSONArray.parseArray(whiteBoardBook);
Iterator<Object> iterator = whiteBoardBookList.iterator();
while (iterator.hasNext()) {
JSONObject object = (JSONObject) iterator.next();
stringBuilder.append(object.get("id"));
if(iterator.hasNext()) {
stringBuilder.append(",");
}
}
注:JSON不用转list或map或ObJect,可以直接使用JSONArray,JSONObject,JSONObject来代替处理数据。