JSON没有被jQuery解析(错误给出)

JSON not being parsed by jQuery (error given)

本文关键字:错误 解析 jQuery JSON      更新时间:2023-09-26

我检查了与此类似的其他问题,并且在我看到的那些问题中,问题要么是无效的JSON,要么是XMLHttpRequest上的头有问题。我的都不是。

我有一个服务器,给我有效的json。但是,当我这样做时:

$.ajax({
            url: 'http://futdata.esy.es/data.php',
            data: {
                'type': 'json'
            },
            type: 'GET',
            success: function (response) {
                console.log(response)
                console.log($.parseJSON(response));
            }
        });

我得到这个:

[{"a":"a", "b":"b"}] Uncaught SyntaxError: Unexpected token

为什么会发生这种情况?我做错了什么?

在响应中似乎有一个NUL字符:

console.log(JSON.stringify(response));
// "['u0000{'"a'":'"a'", '"b'":'"b'"}]"
//   ^^^^^^

虽然它在空格内,JSON.parse()$.parseJSON()仍然不期望它。