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 Introducing JSONObject

Didn't get this JSONObject

Hello.

I Didn't actually get this JSONObject method that we write can somebody explain it to me please?

1 Answer

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

Sure. So we've got our JSON data as a String, which is great, but it's kind of hard to access any individual piece of data in that String. JSONObject takes in the JSON String and gives us an object that makes it a lot easier to access each piece of data.

Hey Ben thanks for answering! i have 2 more question please...1 the JSON data String is that response.body.string? and 2 i dindnt get what is that string name? like we wrote "timezone"?

Ben Deitch
Ben Deitch
Treehouse Teacher
  1. Yep! You can log this and you should see a long String of JSON data.
  2. To get a piece of String data from a JSONObject you use the 'getString' method and pass in the name of that data. So we're just retrieving the 'timezone' property from our JSONObject.

Ohhhh thank you very very much! :)