【发布时间】:2014-01-11 13:47:45
【问题描述】:
我有动态 AJAX JSON 响应对象数据变量
var Data = {"categories":
[
{"Id":"2","CategoryName":"Womens"},
{"Id":"3","CategoryName":"Mens"},{"Id":"4","CategoryName":"Kids"},
{"Id":"5","CategoryName":"Home"},{"Id":"6","CategoryName":"Health and Beauty"},
{"Id":"7","CategoryName":"Seasonal Events"},{"Id":"10","CategoryName":"Model Shots"},
{"Id":"11","CategoryName":"Product Shots"},
{"Id":"12","CategoryName":"Accessories"},
{"Id":"13","CategoryName":"Tops"},{"Id":"14","CategoryName":"Spuds"},
{"Id":"15","CategoryName":"EVIAN"}
],
"brands_cat":{
"_bandCount":{"171": "BrandId" : "171", "ArchiveName": "HP",
"img_from_archive":"7"}
}
}
};
当我在循环中使用并检查 undefined 时,工作正常
for(var i in Data.categories){
if(typeof Data.categories[i] == 'undefined'){
alert(i+"Cat undefined");
}
}
但是当我使用typeof来检查undefined时,
for(var i in Data.categories){
if(typeof Data.brands_cat._catCount[i].total == 'undefined'){
alert(i+"Cat total undefined");
}
}
它给出了错误
TypeError: Data.brands_cat._catCount is undefined
是否可以使用 typeof 关键字检查未定义的多级 JSON 对象
【问题讨论】:
标签: javascript ajax arrays json