2013-01-01 170 views
0

如何從以下 使用此URL解析代碼的messge,calctime,市,ID,國家名稱檢測天氣:http://openweathermap.org/data/2.1/forecast/city/524901使用JSON解析

{ "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

使用下面的代碼解析代碼,messge,calctime,city,id,country,name from上面的url,它會解決你的問題。

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");