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

Code Challenge / Task 3 - Build a Blog Reader Android App -> Getting Data from the Web -> Parsing Data Returned in JSON Format

I'm working on the Code Challenge / Task 3 for Build a Blog Reader Android App -> Getting Data from the Web -> Parsing Data Returned in JSON Format.. The task says

"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'."

My code is

JSONArray jsonBooks = jsonData.getJSONArray("books");
for(int i = 0; i < jsonBooks.length(); i++){

JSONObject book0 = jsonBooks.getJSONObject(i);
String title0 = book0.getString("title");
String pages0 = book0.getString("pages");
Log.i("CodeChallenge", "Book title " + title0 + ", " + pages0);

}

Could someone please tell me what is not coded correctly or point me toward the coding error?

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hi John,

Check out this other Forum post--that should get you what you need!

Thank you sir. I didn't even think of the getstring vs non string info. So used to javascript. Thank you again and for the late pm response.