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
Michael McDonald
2,877 PointsDid we really need to use the getJSONObject method besides just to follow the video?
Instead of writing
titles[i] = jsonVideos.getJSONObject(i).getString("title");
could we have used something like this?
titles[i] = jsonVideos.get(i).title.toString();
/*** This code is an excerpt from a class that extends ListActivity ***/
JSONArray jsonVideos = jsonData.getJSONArray("videos");
String[] titles = new String[jsonVideos.length()];
// Write for loop here!
{
"id":"PL4C60560903672EF7",
"author":"gotreehouse",
"title":"Just For Fun",
"description":"Just plain old funny videos.",
"videos":[
{
"id":"UQzBS4eGtl0",
"uploaded":"2013-02-06T15:37:37.000Z",
"uploader":"gotreehouse",
"category":"Education",
"title":"Treehouse Just Landed!"
},
{
"id":"jQNXtyoyHic",
"uploaded":"2012-04-25T14:51:19.000Z",
"uploader":"gotreehouse",
"category":"Entertainment",
"title":"Meet Mike the Frog | Treehouse"
},
{
"id":"fHpAQadEZIs",
"uploaded":"2013-02-06T15:37:31.000Z",
"uploader":"gotreehouse",
"category":"Education",
"title":"Getting Started with HTML5 JavaPress"
},
{
"id":"PKFPW3do6ks",
"uploaded":"2013-02-06T15:37:41.000Z",
"uploader":"gotreehouse",
"category":"Education",
"title":"EYC Outtakes with Mike the Frog"
}
]
}