gpt4 book ai didi

jquery - 循环动态 JSON 字符串

转载 作者:行者123 更新时间:2023-12-01 02:25:03 25 4
gpt4 key购买 nike

我有一个 POST 请求,该请求收到一个 JSON 字符串作为结果。字段、值或数组有多深?这些都是未知数。因此,我需要循环遍历每个 json 值、其索引及其值,并根据它们执行操作。

$.post(
"test.php",
{ action: 'someaction', param: '2' },
function(data) {
//now data is a json string
$.each(data, function() {
key = data.key; //i need to retrieve the key
value = data.value; //i need to retrieve the value also

//now below here, I want to perform action, based on the values i got as key and values
}
},
"json"
);

如何获取分隔为 keyvalue 的 JSON 值?

最佳答案

抱歉,伙计们,但我自己解决了这个问题。请不要生我的气。 (如果社区有要求,我会删除该问题。)

$.post(
"test.php",
{ action: 'someaction', param: '2' },
function(data) {
//now data is a json string
$.each(data, function(key,value) {
alert(key+value);
//now below here, I want to perform action, based on the values i got as key and values
}
},
"json"
);

关于jquery - 循环动态 JSON 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5460060/

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