Reputation:
I have the following JSON.
{
"lang": [
{
"SECTION_NAME": {
"english": "My title"
},
"SECTION_NAME_2": {
"english": "My title"
}
}
]
}
And I'm looking to print the value like this:
$.getJSON('json/lang.json', function(data) {
var text = data['lang']['SECTION_NAME'];
$('#title').html(text.english);
});
But I have the following error:
TypeError: undefined is not an object (evaluating 'text.english')
Any help please.
Thanks.
Upvotes: 0
Views: 53
Reputation: 25352
You have to access it via index as lang
is an array of object
like this
console.log(data['lang'][0]['SECTION_NAME'])
Upvotes: 1
Reputation: 943537
The value of lang
is an array which contains an object.
You are ignoring the array and trying to access the objects as if it was the value of lang
directly.
Upvotes: 1