访问嵌套的JSON对象 [英] Accessing nested JSON objects
问题描述
我建立一个角度应用程序,也采用了棱角分明翻译为它需要双语言版本。
I'm building an Angular App and also using angular translate as it needs to be in dual languages.
我已经的看起来的已经创造了我正确的JSON(运行它通过检查),但是当我尝试JSON对象中访问项目第1级,则返回undefined。
I've seem to have created my JSON properly (ran it through a checker), but when I try to access items within the JSON object beyond the first level, it returns undefined.
有关实例中,角翻译内我的JSON是这样的:
For instance, my JSON within the angular translations is this:
$translateProvider.translations('en', {
"SEARCH": {
"SEARCH" : "Recherce",
"ABILITY" : "Abilities",
"MANAGEMENT" : "Management Competencies",
"PERSONAL" : "Personal Suitability"
},
"ABILITIES": {
"TITLE" : "Test Title here",
"ADVISORY": {
"TITLE" : "Advisory Skills",
"QUESTIONS": [
{
"TYPE" : "A",
"LEVEL" : "45",
"DESCRIPTION" : "Can you tell me how awesome you are"
},
{
"TYPE" : "B",
"LEVEL" : "100",
"DESCRIPTION" : "Tell me about your wicked project"
}
]
}
},
"HEADLINE": "Oh No!",
"SUB_HEADLINE": "Looks like you are not amazing"
});
,并开始在JSON对象访问数据,我
And to begin accessing the data in the JSON object, I do
list = $translateProvider.translations('en');
现在,输出在控制台项目时,看看他们的工作我这样做:
Now, when outputting items in the console to see if they work I do this:
console.log(list);
var getTitle = list.HEADLINE;
var getSearch = list.SEARCH.ABILITY;
console.log(getSearch);
console.log(getTitle);
这是它得到奇数。
在'名单'返回JSON数组我指定
The 'list' returns the JSON array I specified
获取 HEADLINE
收益哦,不!
但是,让 list.SEARCH.ABILITY
返回未定义
是什么给了!?我还没有尝试过的事件访问的东西,我真正想要的真正的嵌套数组中的能力
What gives!? I haven't event tried to access the stuff I really want in the really nested array "ABILITIES"
请记住,角翻译使用格式 {{'ABILITIES.ADVISORY.TITLE|翻译}}
来输出JSON到HTML页面
Keep in mind that Angular Translate uses the format {{ 'ABILITIES.ADVISORY.TITLE' | translate }}
to output the JSON onto the HTML page
推荐答案
尝试 list.SEARCH [能力。值
这篇关于访问嵌套的JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!