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.
 asked Nov 2, 2015 at 21:01
 
 
 
 user4072347
 
 
2 Answers 2
You have to access it via index as lang is an array of object
like this
console.log(data['lang'][0]['SECTION_NAME'])
 answered Nov 2, 2015 at 21:04
 
 
 
 Anik Islam Abhi 
 
 25.4k8 gold badges61 silver badges82 bronze badges
 
 
 Sign up to request clarification or add additional context in comments.
 
 
 
 3 Comments
Anik Islam Abhi
 then object design should be 
  { lang : { section : { english : 'My title' } } @robertoAnik Islam Abhi
 oh my bad :( , 
  { lang : { SECTION_NAME : { english : 'My title' } } . now try :) @robertoThe 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.
 answered Nov 2, 2015 at 21:03
 
 
 
 Quentin 
 
 948k136 gold badges1.3k silver badges1.4k bronze badges
 
 Comments
lang-js