1

我在尝试调用和解析一些 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 方法)同样的问题仍然存在。

4

2 回答 2

1

正如@Malti 和@CBroe 上面指出的那样,问题与 dataType: 'json' 有关 - 问题已解决。

于 2013-05-30T16:27:57.117 回答
0

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

于 2013-05-30T16:18:48.463 回答