我正在尝试从 PHP 获取一个数组并使用 jQuery 进一步操作它。在我的 PHP 文件中echo json_encode($data)
,当我在 jQuery 的响应中添加警报时,我得到:
[
{
"CustomerID": "C43242421",
"UserID": "432421421",
"Customer": "rqewrqwreeqwr",
"Add1": "rqwerqwreqwrqwrqwr",
"Add2": " ",
"Add3": " ",
"Phone": "4131231",
"Fax": "532442141",
"Contact": "reqwrqwrw",
"Email": "gfdgdsg",
"PaymentTerm": null,
"Country": "3231",
"City": "111",
"Zip": " "
}
]
,这是一个有效的 json 数组。现在我尝试进一步做的是将这些对作为键 => 值,就像我在 php 中的关联数组中一样。
$.post("templates/test.php",
{data: query,
cond: $(this).text(),
action: 'select'
},
function(res) {
alert(res) //outputs what i pasted above
$.each($.parseJSON(res), function(key, value) {
alert(key + value);
//this outputs: 0[object Object]
});
删除$.parseJSON
上面的函数会给我一个invalid 'in' operand e on jquery.min.js(line 3)
Firebug 错误日志。你能帮我解决我的麻烦吗?