pravin khandbahale
pravin khandbahale

Reputation: 1

Detecting weather using JSON parsing

How to parse code, messge, calctime,city,id,country, name from following use this URL : 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
                    },

Upvotes: 0

Views: 603

Answers (2)

Dipak Keshariya
Dipak Keshariya

Reputation: 22291

Use below code for parse code, messge, calctime,city,id,country, name from above url, it will solve your problem.

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

Upvotes: 1

Taruni
Taruni

Reputation: 1671

Follow the below code:

JSONObject jObj=new JSONObject(jsonResponse);
String msg=jObj.getString("message");
String calctime=jObj.getString("calctime");

Upvotes: 4

Related Questions