内容导航:
1、
parse json error
2、
json接口返回错误?
1、
parse json error
英:
美:
常见释义:
解析json错误
2、
json接口返回错误?
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
{$i}2
{$i}4
{$i}6
{$i}8
{$i}2
{$i}4
{$i}6
{$i}8
可以发现 JSON.parse() 的参数必须符合 JSON字符串 的格式才可以被正确的转换为对象,否则可能会引起报错,从而对其它的代码造成影响。