请问一下JSON怎么存储和提取List表或数组?
发布网友
发布时间:2022-04-20 00:20
我来回答
共1个回答
热心网友
时间:2022-04-20 01:49
// json
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String, String> map = new HashMap<String, String>();
map.put("name", "张三");
map.put("age", 22 + "");
list.add(map);
JSONObject object = new JSONObject();
try {
object.put("glass", "7年级");
object.put("stus", list);
} catch (JSONException e) {
e.printStackTrace();
}
StringBuffer sbBuffer = null;
try {
map = ((List<Map<String, String>>) object.get("stus")).get(0);
sbBuffer = new StringBuffer(map.get("name") + ":" + map.get("age"));
} catch (JSONException e) {
e.printStackTrace();
}