如何从以下解析代码,信息,calctime,城市,ID,国家/地区,名称
使用此网址:http://openweathermap.org/data/2.1/forecast/city/524901
{ "cod":"200","message":"kf","calctime":0.0342,"url":"http:\/\/openweathermap.org\/city\/524901",
"city":
{
"id":524901,
"coord":
{
"lon":37.615555,"lat":55.75222
},
"country":"RU","name":"Moscow","dt_calc":1356948005,"stations_count":6
},
答案 0 :(得分:4)
请按照以下代码:
JSONObject jObj=new JSONObject(jsonResponse);
String msg=jObj.getString("message");
String calctime=jObj.getString("calctime");
答案 1 :(得分:1)
使用以下代码解析代码,信息,calctime,城市,ID,国家/地区,名称来自上面的网址,它将解决您的问题。
JSONObject mJsonObj = new JSONObject(mJsonResponse);
String mCode = mJsonObj.getString("cod");
String mMessage = mJsonObj.getString("message");
String mCalcTime = mJsonObj.getString("calctime");
JSONObject mJsonCityObj = mJsonObj.getJSONObject("city");
String mId = mJsonCityObj.getString("id");
String mConuntry = mJsonCityObj.getString("country");
String mName = mJsonCityObj.getString("name");