如:
jsonData的数据格式:[{ "name": "xiaowang", "password": "123" },{ "name": "xiaozhang", "password": "456" },{ "name": "xiaoli", "password": "789" }]
import org.json.JSONArray;
import org.json.JSONObject;
private JSONArray arr;
arr = new JSONArray(jsonData);
for(int i=0;i<arr.length();++i){
JSONObject temp = (JSONObject) arr.get(i);
map.clear();
map.put("materialName", temp.getString("materialName"));
map.put("materialFormat", temp.getString("unitName"));
map.put("id", temp.getString("id"));
listItem.add(map);
}
本文介绍了一种将JSON数据格式的数组转换为Java中List集合的方法。通过使用org.json库中的JSONArray和JSONObject类,可以方便地解析每个元素,并将其转换为Map对象存储在List中。该过程展示了如何迭代JSON数组并获取指定字段。
3182

被折叠的 条评论
为什么被折叠?



