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 trialTremayne Clinton
5,417 PointsNeed some help pls
Trying to write a for loop what am I doing wrong
JSONArray jsonShows = jsonData.getJSONArray("jsonShows");
for (int i = 0; i < data.length(); i++){
JSONObject = data.getJSONObject(i);
Show show = new Show();
show.setTitle(jsonShows.getJSONObject("title"));
show.setSeason(jsonShows.getJSONObject("season"));
show.setEpisode(jsonShows.getJSONObject("title"));
Log.i(TAG, "CodeChallenge:");
}
// JSONObject 'jsonData' was loaded from data.jso
{
"name":"Netflix Playlist",
"shows":[
{
"title":"Doctor Who",
"season":8,
"episode":3
},
{
"title":"Arrow",
"season":1,
"episode":10
},
{
"title":"Portlandia",
"season":4,
"episode":5
}
]
}
1 Answer
Jon Kussmann
Courses Plus Student 7,254 PointsIn the first line of your for loop, you have not created a name for the variable to hold the JSON object.
I think you meant to have: JSONObject jsonShows= data.getJSONObject(i);
Tremayne Clinton
5,417 PointsTremayne Clinton
5,417 PointsNo that did'nt work
Jon Kussmann
Courses Plus Student 7,254 PointsJon Kussmann
Courses Plus Student 7,254 PointsSorry, I had to go back and actually look at the question you were referring to.
jsonShows is the array that you want to loop through... so that is the object you want to check the length of to define the for loop. You are creating an object of the Show class (or at least are trying to), but you don't have one defined (not that you need it for this question).
The "CodeChallenge" is the TAG that you want to use, and for the second parameter of the Log.i method, you want the title of the show.
Does that make sense?
Tremayne Clinton
5,417 PointsTremayne Clinton
5,417 PointsI'll watch the video 5 or 6 more times to see if I can see what he wants me to do
Jon Kussmann
Courses Plus Student 7,254 PointsJon Kussmann
Courses Plus Student 7,254 PointsIs there a section of the code I posted here that does not make sense?
Tremayne Clinton
5,417 PointsTremayne Clinton
5,417 Pointsjust leaning less than a week so it all new to me I follow the example just mean I need more work
on understanding what I'm to do