我想在json中解析嵌套对象,但我找不到解决方案。
我的Json是:
{"status":"ok","response":
{"1":[
{"Albert 1er":{"id":"74400610","lat":"43.6165153431063","lon":"3.87407454752208","name":"Place Albert 1er","town":"Montpellier","lines":[]}},
{"Antigone":{"id":"74401726","lat":"43.6085958455429","lon":"3.8866476240206","name":"Antigone","town":"Montpellier","lines":[]}}
]}
}
我的代码是:
JSONObject json = jsonParser.makeHttpRequest(url, "GET", params);
JSONArray stats = json.getJSONArray("response");
for (int j = 0; j < stats.length(); j++) {
JSONObject c = stats.getJSONObject(j);
// Storing each json item in variable
String nom_station = c.getString("name");
System.out.println(nom_station);
}
答案 0 :(得分:0)
IMO最佳解决方案是使用谷歌Gson lib进行编组和处理包含混合类型的JSON数组
Class Adresse {
String id;
float lat;
float lon;
Sring name;
String town;
Object lines[];
}
Gson gson = new Gson();
gson.fromJson(json, Adresse.class);