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

Javier Briones
seal-mask
.a{fill-rule:evenodd;}techdegree
Javier Briones
Front End Web Development Techdegree Student 29,674 Points

I can't get the last code challenge to work

here's my code:

// JSONObject 'jsonData' was loaded from data.json String name = jsonData.getString("name"); String publisher = jsonData.getString("publisher"); String language = jsonData.getString("language");

JSONArray jsonBooks = jsonData.getJSONArray("posts");

for(int j = 0; j < 50; j++) { JSONObject jsonBook = jsonBooks.getJSONObject(j); String title = jsonBook.getString("CodeY 1, 200"); Log.i("CodeChallenge", "Book " + title);

}

The error just says, "Try again!"

Help please

2 Answers

Dear Javier,

I think you need to alter the loop itself and some of the code:

The "termination" expression should be "j < jsonBooks.lenght()" because you need to be sure the FOR statement will work the exact number of times you need and not '50'.

"for (int j = 0; j < jsonBooks.lenght(); j++)"

Also, the "title" variable is not right. The parameter for "getString" method is the name of the JSON field. I think it shoud be:

String title = jsonBook.getString("title");

Do the same for the page number (use "getInt") and cancatenate all you need!

Try again and let us know.