AJAX 页面返回以下JSON
输出:
{
"39": {
"amount": [
"1503",
"1443",
"1383"
],
"account_number": [
"552247",
"552247",
"552247"
]
},
"40": {
"amount": [
"1289",
"1284",
"1279"
],
"account_number": [
"552247",
"552247",
"552247"
]
},
"41": {
"amount": [
"57",
"52",
"47"
],
"account_number": [
"552247",
"552247",
"552247"
]
}
}
呼叫页面:
$.ajax({
url: 'get_bid_details.php',
type: 'POST',
data: {bidIds:bidList_backup},
dataType: 'json',
success: function(response) {
var arr = $.parseJSON(response); // shows error on this line.
$.each(arr, function(index,val) {
...
...
$.each(arr['amount'], function(ind,val) {
...
...
});
});
}
});
我不知道我犯了什么错误。如何解决这个问题?
提前谢谢。
这是因为它已经被解析了,当你添加json
作为dataType
时,jQuery 会自动执行此操作,所以答案是删除带有 $.parseJSON
的行,因为它已经是一个对象,再次解析它会产生错误。