最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse - Stack Overflow

matteradmin8PV0评论

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', '.json');

ourRequest.onload = function(){
    var ourData  = JSON.parse(ourRequest.resoponseText);
    console.log(ourData[0]);
};
ourRequest.send();

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();
Share Improve this question asked Sep 4, 2017 at 20:00 Mssol94Mssol94 171 silver badge4 bronze badges 1
  • 2 it looks like you have a typo, i imagine it should be responseText. – Paul Fitzgerald Commented Sep 4, 2017 at 20:03
Add a ment  | 

2 Answers 2

Reset to default 6

You've simply misspelt resoponseText - It should be responseText. You get the error because JavaScript ends up calling JSON.parse("undefined").

You have a typo: you wrote ourRequest.resoponseText rather than ourRequest.responseText.

Post a comment

comment list (0)

  1. No comments so far