我有一个JSON对象,我想检查该JSON对象中是否设置了键。
这是JSON对象:
这是JSON对象:
var Data_Array = {
"Private": {
"Price": {
"Adult": "18",
"Child": [{
"FromAge": "0",
"ToAge": "12",
"Price": "10"
}]
}
}
}
如果 JSON 对象像这样,你可以看到它不存在Child这个属性,那么如何进行检查?
If JSON Object like this as you can see Child is not exist, then how to check this
var Data_Array = {
"Private": {
"Price": {
"Adult": "18"
}
}
}
我已经尝试过
if(Data_Array.Private.Price.Child[0].Price != "undefined"){
...
}
但是它显示了这个错误
未捕获的类型错误:无法读取属性
我无法找出该怎么做。
Data_Array.Private.Price.hasOwnProperty("Child")
可以翻译为:数据数组私有的价格是否拥有"Child"属性。 - VLAZ