Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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! :)