【发布时间】:2016-03-10 12:32:42
【问题描述】:
我正在尝试使用以下代码访问 JSON 对象键。
JSONObject mainObject = new JSONObject(response);
JSONObject posts = mainObject.getJSONObject("_id");
Map<String, JSONObject> map = (Map<String,JSONObject>)posts.getMap();
ArrayList<String> list = new ArrayList<String>(map.keySet());
System.out.println(list);
我的 JSON 数组是:
[{"_id": "Grocery", "Categories": [{"Pulses and Grains": ["Dals"]}, {"Beverages": ["Juices", "Tea", "Coffee", "Soft Drinks"]}]}, {"_id": "Stationary", "Categories": [{"Chart Paper": ["A4 Size Chart Paper", "A3 Size Chart Paper"]}]}]
我的项目不是任何 Android 项目,但我必须使用这一行来获取项目中 JSON 的所有键及其值。问题在于它在 .getMap() 下显示红线,并说它无法找到符号。请让我知道我应该导入什么来完成这项工作,请记住这不是任何 Android 项目
【问题讨论】: