How To Read Multi-level Json
Solution 1:
Try this:
data.items[0].snippet.title
Explanation (you can see corresponding object in /* */
comment):
items[0];
/*
{
'snippet': {
'title': 'YouTube Developers Live: Embedded Web Player Customization'
}
}
*/
items[0].snippet;
/*
{
'title': 'YouTube Developers Live: Embedded Web Player Customization'
}
*/
items[0].snippet.title;
/*
'YouTube Developers Live: Embedded Web Player Customization'
*/
Solution 2:
As addition to madox2's answer, here's an explanation:
{
"items": [
{
"snippet": {
"title": "YouTube Developers Live: Embedded Web Player Customization"
}
}
]
}
The root is a Object, while items
is an array. Objects are surrounded by curly braces, while arrays are surrounded by sqare braces.
In JS, you can access a Object like this:
parent.child
In your case, assuming you the data is assigned to a variable called data
, you would access it with the variable name and the object you want to get:
data.items
Array's have keys - if no keys are specified, the keys will be number-based.
So seeing that items
is an array without any key specified, you'll have to access the x-th element. x
is in your case 0, because it's the first item of the array (Remember, arrays are zero-indexed):
data.items[0]
And here you have a object again, so access it:
data.items[0].snippet.title
Post a Comment for "How To Read Multi-level Json"