【发布时间】:2011-07-24 12:31:54
【问题描述】:
我有一个 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"
);
如何获取分隔为key 和value 的JSON 值?
【问题讨论】: