[英]JSON object returns as undefined
I am confused as to why this is alterting as "undefined". 我对为什么将其更改为“未定义”感到困惑。 Any help would be much appreciated as I am stuck on an important project.
由于我被困在一个重要的项目上,任何帮助将不胜感激。
JavaScript JavaScript的
$.getJSON("item-data.json", function(results) {
$.each(results, function(index) {
alert(results[index].CatalogEntryView);
});
});
JSON Data is a BIG file. JSON数据是一个BIG文件。 It starts out with the first object defined as "CatalogEntryView" with a long list of nested properties.
它从定义为“ CatalogEntryView”的第一个对象开始,其中包含一长串嵌套属性。
{
"CatalogEntryView": [
{
"CustomerReview": [
Using the following code recommended in one of the answers below returns the following to the console: 使用以下答案之一中建议的以下代码将以下内容返回到控制台:
Recommended Code 推荐代号
$.each(results.CatalogEntryView, function(index, item) {
console.dir(item.CustomerReview);
});
If I understood you correctly, try this: 如果我对您的理解正确,请尝试以下操作:
$.each(results.CatalogEntryView, function(index, item) {
console.dir(item.CustomerReview);
});
It should fit the structure of your json file. 它应该适合您的json文件的结构。 Another question is what you really want to get...
另一个问题是您真正想要得到什么...
results
from your code should be iterable : 代码的
results
应该是可迭代的 :
jQuery.each( array, callback ) - a generic iterator function, which can be used to seamlessly iterate over both objects and arrays.
jQuery.each(array,callback)-一个通用的迭代器函数,可用于无缝迭代对象和数组。 Arrays and array-like objects with a length property (such as a function's arguments object) are iterated by numeric index, from 0 to length-1.
具有长度属性的数组和类似数组的对象(例如函数的arguments对象)通过从0到length-1的数字索引进行迭代。 Other objects are iterated via their named properties.
其他对象通过其命名属性进行迭代。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.