1 JSONArray JSONObject
JSONArray array = JSONArray.fromObject(topics);
for (int i = 0; i < array.size(); i++) {
JSONObject jsonObject = array.getJSONObject(i);
String topicId = jsonObject.getString("topicId");
String answer = jsonObject.getString("answer");
map.put(topicId, answer);
}
2 json-->list-->json
JsonConfig jsonConfig = new JsonConfig();
Map<String, Class> classMap = new HashMap<String, Class>();
classMap.put("answer", String.class);
classMap.put("imgs", String.class);
jsonConfig.setClassMap(classMap);
jsonConfig.setRootClass(HwCompleteContentJson.class);
JSONArray answerJsonArr = JSONArray.fromObject(answerJson);
List<HwCompleteContentJson> answerJsonList = new ArrayList<HwCompleteContentJson>();
//将学生作答json转成HwCompleteJsonBean格式。
answerJsonList = (List<HwCompleteContentJson>) JSONArray.toCollection(answerJsonArr, jsonConfig);
JSONArray hwCompleteJsonBeanListArray = JSONArray.fromObject(answerJsonList);
String hwCompleteJson = hwCompleteJsonBeanListArray.toString();//学生作答详情jsonStr
<span style="white-space:pre"> </span>List<HwCompleteContentJson> answerJsonList = new ArrayList<HwCompleteContentJson>();
<span style="white-space:pre"> </span>JSONArray answerJsonArr = JSONArray.fromObject(content);
List<HwCompleteContentJson> answerJsonList = new ArrayList<HwCompleteContentJson>();
answerJsonList = (List<HwCompleteContentJson>) JSONArray.toCollection(answerJsonArr, HwCompleteContentJson.class);
3. json --> map
Object obj = JSONObject.toBean(JSONObject.fromObject(content),HashMap.class);
JSONObject.fromObject(map)