我很困惑,为什么这被指定为“undefined”。任何帮助将非常感谢,因为我被困在一个重要的项目。JSON对象返回为undefined
的JavaScript
$.getJSON("item-data.json", function(results) {
$.each(results, function(index) {
alert(results[index].CatalogEntryView);
});
});
JSON数据是一个大的文件。它首先将第一个对象定义为“CatalogEntryView”,并带有一长串嵌套属性。
{
"CatalogEntryView": [
{
"CustomerReview": [
使用下面的答案的一个建议下面的代码返回以下控制台:如果我理解正确的,你
推荐码
$.each(results.CatalogEntryView, function(index, item) {
console.dir(item.CustomerReview);
});
我们需要更多关于JSON文件的结构以及“返回”是什么意思的信息。 –
它警告“未定义” – SDH
如果它始于'CatalogEntryView',那么'index'就是这样。因此'results [index]'将成为'results ['CatalogEntryView']'因此'results ['CatalogEntryView']。CatalogEntryView'没有定义,因为没有这样的属性 –