如果我的 JSON 对象看起来像这样:
{
"weather:{
"sunny": "yes"
"wind": "48mph"
"location":{
"city": "new york"
"zip": "12345"
}
}
"rating": "four stars"
}
我如何访问城市名称?我可以使用 optString 获取所有“天气”或“评级”,但如何获取其中的信息?
最佳答案
很简单
JSONObject jsonObj = new JSONObject(jsonString);
JSONObject weather = jsonObj.getJSONObject("weather");
JSONObject location = weather.getJSONObject("location");
String city = location.getString("city");
关于java - 如何使用 java 访问 android 中的嵌套 JSON 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24917509/