I Am trying to parse a Youtube playlist:
If my JSON is structured like:
{"apiVersion" ....
"items":[{"id2":"some-id","title":"songtitle",
I am perfectly able to parse the title via:
// Fill array
NSArray *items = [json objectForKey:@"items"];
// Get item from tableData
NSDictionary *item = [tableData objectAtIndex:[indexPath row]];
// Set text on textLabel
[[cell textLabel] setText:[item objectForKey:@"title"]];
But if the JSON is like:
{"apiVersion" ....
"items":[{"id1": .... "video":{"id2":"some-id","title":"songtitle",
How can i reach the nested object title?
Just a simple thing, but i am banging my head on this for hours now. Gets frustrating, thanks for your suggestions!
[EDIT]
This is the full structure:
{
"items":
[
{
"video":
{
"title": "Number One",
"description": "Description one"
},
{
"title": "Number two",
"description": "Description two"
},
{
"title": "Number three",
"description": "Description three"
}
},
{
"video":
{
"title": "Number One",
"description": "Description one"
},
{
"title": "Number two",
"description": "Description two"
},
{
"title": "Number three",
"description": "Description three"
}
}
]
}
The problem is that your json is not valid. All the
titlesshould be in array right? So they have to be in [ ]. You can use for example the following site to “debug” your json:http://jsonformatter.curiousconcept.com/
Also, in iOS 5 you can use the new built-in JSON api. Here is a nice tutorial for that:
http://www.raywenderlich.com/5492/working-with-json-in-ios-5
Nevertheless, here is how your json should look like I guess:
Good luck with your project 😉