我在尝试调用和解析一些 JSON 时遇到了一些问题。我收到的错误是SCRIPT1014: Invalid Character这个问题在所有浏览器中普遍发生,而不仅仅是 Internet Explorer。
查询:
$.ajax({
type: "POST",
url: "enquiries.php?show=all",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
var obj = $.parseJSON(msg);
console.log(obj);
}
});
输出 JSON:
{"0":{"ID":"1","first_name":"test","last_name":"test","email_address":"test","daytime_tel":"34343434","mobile_tel":"343434","comments":"sdfsdfsdfsdfsdfsdf","location_url":"32423452322resdfsdfxdf","date_of_submit":"2013-05-30","time_of_submit":null,"marked_as_read":"0","sender":"test test"}}
我已使用 JSONLint 将其检查为有效的 JSON:
{
"0": {
"ID": "1",
"first_name": "test",
"last_name": "test",
"email_address": "test",
"daytime_tel": "34343434",
"mobile_tel": "343434",
"comments": "sdfsdfsdfsdfsdfsdf",
"location_url": "32423452322resdfsdfxdf",
"date_of_submit": "2013-05-30",
"time_of_submit": null,
"marked_as_read": "0",
"sender": "test test"
}
}
我还尝试包含一个单独的文件来打印 JSON(而不是 enquiries.php?view=all 方法)同样的问题仍然存在。