本文介绍了未捕获到的SyntaxError:JSON中的意外令牌u在JSON.parse的位置0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试学习JavaScript,并且不断收到错误消息未捕获的SyntaxError:JSON中的意外令牌u在JSON.parse的位置0".
I'm trying to learn JavaScript and I keep getting the error "Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse".
var ourRequest = new XMLHttpRequest();
ourRequest.open('GET', 'https://learnwebcode.github.io/json-example/animals-1.json');
ourRequest.onload = function(){
var ourData = JSON.parse(ourRequest.resoponseText);
console.log(ourData[0]);
};
ourRequest.send();
推荐答案
您只是拼写了resoponseText
-应该是responseText
.因为JavaScript最终调用JSON.parse("undefined")
,所以得到了错误.
You've simply misspelt resoponseText
- It should be responseText
. You get the error because JavaScript ends up calling JSON.parse("undefined")
.
这篇关于未捕获到的SyntaxError:JSON中的意外令牌u在JSON.parse的位置0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!