为什么这在以下示例中不显示任何内容?
$.getJSON('test.json', function (data) {
$.each(data.glossary, function (index, val){
var title = val.title, //"example glossary"
term = val.GlossDiv.GlossList.GlossEntry.GlossTerm; //"Standard Generalized Markup Language"
$('ul#results').append('<li><div class="name">' +this.title+ '</div></li><li><div class="name2">' +term+ '</div></li>');
});
});
我必须遍历对象才能从复杂的嵌套 JSON 数据文件中获取某些值,如下所示:
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "Hello!!",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}