[英]Can't get json data inside array
[
{
"May": [
{
"year": 1994,
"date": "2"
},
{
"Sequence": 2,
"Type": "Images"
}
],
"_id": "1122"
}
]
I can get id except "date" which is inside array. 除了数组中的“日期”,我可以获取ID。 And date just show me
undefined
. 日期只是给我看
undefined
。
var data = [ { "May": [ { "year": 1994, "date": "2" }, { "Sequence": 2, "Type": "Images" } ], "_id": "1122" } ]; alert(data[0].May[0]["date"]);
You should use arr[i].May[0]['date']
, date
is inside the object of the 0th index of array May. 您应该使用
arr[i].May[0]['date']
, date
位于数组May的第0个索引的对象内。
Array will be start with the index 0 only . 数组将仅从索引0开始。 so from your json data 0th position only have the key named "date".
因此,从您的json数据的第0个位置起,只有名为“ date”的键。 So you should use like @void answer .
因此,您应该使用@void答案 。 If you had doubt about whether data is have or not use like below
如果您对数据是否有使用存有疑问,如下所示
if(data[0].May[0]["date"])
alert(data[0].May[0]["date"]);
Thank you :) 谢谢 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.