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 Blog Reader Android App Getting Data from the Web Parsing Data Returned in JSON Format

Having trouble with, parsing data returned in JSON format objective three.

The objective question follows below.

Finally, write a 'for' loop that loops through 'jsonBooks'. In each step of the loop, use 'getJSONObject(int index)' to get a JSONObject from the array. Then use the 'Log.i()' method (with "CodeChallenge" as the tag) to write the book title, a comma, a space, and the number of pages. Ex. output: 'Book title 1, 300'.

Not quite sure how I am supposed to do this part. Any help is greatly appreciated.

2 Answers

Hey Jeremiah,

For the next question, remember posting the code you are having issues so we can help you based on your mistakes.

For now, to solve your code, the answer should be something like this

  for (int i=0; i<jsonBooks.length(); i++){
  JSONObject jsonBook = jsonBooks.getJSONObject(i);
  Log.i("CodeChallenge", jsonBook.getString("title") + ", " + jsonBook.getInt("pages"));
  }

Thanks! Alright, I'll be sure to do that next time, thanks for the input!

Cool, add it as the best answer then

Good luck!