0

如何使用以下 URL 解析代码、消息、计算时间、城市、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
                    },
4

2 回答 2

4

按照下面的代码:

JSONObject jObj=new JSONObject(jsonResponse);
String msg=jObj.getString("message");
String calctime=jObj.getString("calctime");
于 2013-01-01T05:56:09.647 回答
1

使用下面的代码从上面的 url 解析代码、messge、calctime、city、id、country、name,它将解决您的问题。

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");
于 2013-01-01T06:08:44.673 回答