如何使用java访问android中的嵌套JSON数据?
如果我的JSON对象看起来像这样:如何使用java访问android中的嵌套JSON数据?,java,android,json,Java,Android,Json,如果我的JSON对象看起来像这样: { "weather:{ "sunny": "yes" "wind": "48mph" "location":{ "city": "new york" "zip": "12345" } } "rating": "four stars" } 如何访问城市名称?我可以使用optString获取所有的“天气”或“评级”,但如何获取其中的信息呢?非常简单 JSONObject json = new JSONObjec
{
"weather:{
"sunny": "yes"
"wind": "48mph"
"location":{
"city": "new york"
"zip": "12345"
}
}
"rating": "four stars"
}
如何访问城市名称?我可以使用optString获取所有的“天气”或“评级”,但如何获取其中的信息呢?非常简单
JSONObject json = new JSONObject(yourdata);
JSONObject weather = json.getString("weather");
weather.getString("sunny"); //yes
weather.getString("wind"); //46mph
JSONObject location = new JSONObject(weather.getString("location"));
location.getString("city"); // new york
json.getString("rating"); //...
JSONObject jsonObj = new JSONObject(jsonString);
JSONObject weather = jsonObj.getJSONObject("weather");
JSONObject location = weather.getJSONObject("location");
String city = location.getString("city");
请仔细阅读这很简单
JSONObject jsonObj = new JSONObject(jsonString);
JSONObject weather = jsonObj.getJSONObject("weather");
JSONObject location = weather.getJSONObject("location");
String city = location.getString("city");
请仔细阅读这很简单
JSONObject jsonObj = new JSONObject(jsonString);
JSONObject weather = jsonObj.getJSONObject("weather");
JSONObject location = weather.getJSONObject("location");
String city = location.getString("city");
请仔细阅读这很简单
JSONObject jsonObj = new JSONObject(jsonString);
JSONObject weather = jsonObj.getJSONObject("weather");
JSONObject location = weather.getJSONObject("location");
String city = location.getString("city");
通读