Reena Reena - 6 months ago 8
JSON Question

Get JSON Response in Android for Weather?

I have develop the weather App and I want to use this URL,
http://api.openweathermap.org/data/2.5/weather?lat=11.11111&lon=22.2222

and get the information only, country,sunrise,sunset,temp_min,temp_max,name.
How get the response?

please suggest me.
Thanks.

{
sys: {
message: 1.3106,
country: "IN",
sunrise: 1426123283,
sunset: 1426166271
},

main: {
temp: 306.561,
temp_min: 306.561,
temp_max: 306.561,
pressure: 1016.81,
sea_level: 1026.98,
grnd_level: 1016.81,
humidity: 43
},

name: "Sarkhej",
}

Answer
JSONObject one = new JSONObject(json);

JSONObject sys = one.getJSONObject("sys");
String message = sys.getString("message");
String country = sys.getString("country");
String sunrise = sys.getString("sunrise");
String sunset = sys.getString("sunset");

JSONObject main = one.getJSONObject("main");
String temp = main.getString("temp");
String temp_min = main.getString("temp_min");
String temp_max = main.getString("temp_max");
String pressure = main.getString("pressure");
...

String name=one.getString("name");