gpt4 book ai didi

javascript - 使用 jQuery 迭代 JavaScript 对象

转载 作者:行者123 更新时间:2023-11-30 08:14:41 24 4
gpt4 key购买 nike

这是我要解析的对象:

my.test = [{"Customer":
{
"id":"123",
"Name":"john"
}
}]

我已经有了:

$.each(Cmy.test, function(index, value) {
$.each(value.Customer, function(innerIndex, innerValue) {
alert('File ' + innerValue.id + ' in customer ' + index);
});
});

但是我的 alert() 显示 undefined 值。我做错了什么?

最佳答案

my.test = [{"Customer":
{
"id":"123",
"Name":"john",
}

应该是

my.test = [{"Customer": {
"id":"123",
"Name":"john"
}}];

然后像这样迭代:

$.each(my.test, function(index) {
alert('File ' + my.test[index].Customer.id + ' in customer ' + index);
});

至少这就是我认为您正在寻找的。

关于javascript - 使用 jQuery 迭代 JavaScript 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5724206/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com