JSON解析错误SCRIPT 1014无效字符



我在尝试调用和解析一些JSON时遇到了一些问题。我收到的错误是SCRIPT1014:无效字符此问题普遍发生在所有浏览器中,而不仅仅是internet explorer。

Jquery:

    $.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"}}

我已经检查了这是有效的JSON使用JSONLint:

{
"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(而不是查询.php?

正如@Malti和@CBroe在上面指出的问题是与dataType: 'json'有关-问题解决了

除非使用json_encode在queries .php中输出,否则不需要进行解析。我建议使用json_encode.

最新更新