最佳答案:js 报错 Unexpected end of JSON input,Unexpected token u in JSON at position 0JSON 通常用于与服务端交换数据。在接收服务器数
js 报错 Unexpected end of JSON input,Unexpected token u in JSON at position 0
JSON 通常用于与服务端交换数据。
在接收服务器数据时一般是字符串。
我们可以使用 JSON.parse() 方法将数据转换为 JavaScript 对象。
在谷歌浏览器的 Console 调试台中尝试一下这几种参数的返回结果:
JSON.parse(null);
// null
JSON.parse("");
// VM6600:1 Uncaught SyntaxError: Unexpected end of JSON input
JSON.parse(undefined);
// VM6635:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
可以发现 JSON.parse() 的参数必须符合 JSON字符串 的格式才可以被正确的转换为对象,否则可能会引起报错,从而对其它的代码造成影响。