Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Weather App (2015) Working with JSON Setting CurrentWeather from JSON

Ragesh Kanagaraj
Ragesh Kanagaraj
3,637 Points

Declaring JSON object for Forecast and Currently

TO get the Timezone JSONObject was created using jsonData a String type like

JSONObject forecast=new JSONObject(jsonData);

But for humidity and other details why have they declared it using jsonGetObject ie JSONObject currently = forecast.getJSONObject("Currently");

I assume we are doing that in order to get the currently block in that JSON data ??

1 Answer

Hello Ragesh, during 'JSONObject forecast=new JSONObject(jsonData);' we create a Json object named forecast which uses the data that was passed to our method getCurrentDetails. Thus the jsonData is a JSON object which contains our weather data obtained from the forecast api. Now this JSON object has a nested JSON object inside it which gives the currrent weather data. Thus by declaring JSONObject currently = forecast.getJSONObject("currently"); we are getting the JSON data associated with the key "current" and making a new JSON object from it.
Eg jsonData: {key :value key :value key :value current(which is a key): valueJsonObject(which is a JSON object associated with key "currently") }