【问题标题】:UNEXPLAIN ERROR In JAVASCRIPTJAVASCRIPT 中出现无法解释的错误
【发布时间】:2017-11-30 11:06:54
【问题描述】:

我在 javascript 中遇到了这些错误,这让我发疯了我一遍又一遍地查看了代码,我没有发现任何错误我想看看是否可以对此有新的看法: 我看了又看代码,我想我要瞪大眼睛了

好的,我现在修复它,我得到了这个error XML Parsing Error: syntax error Location: file:///Volumes/YOLLIEBLUES/JS.finalProject/question.json Line Number 1, Column 1

SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 24 column 62 of the JSON data
[Learn More]
trivia.js:16:16
loadQuestions/test.onreadystatechange
file:///Volumes/YOLLIEBLUES/JS.finalProject/trivia.js:16:16


XML Parsing Error: syntax error
Location: file:///Volumes/YOLLIEBLUES/JS.finalProject/question.json
Line Number 1, Column 1:

好的,我也解决了这个问题,但我仍然收到该错误

XML Parsing Error: syntax error
Location: file:///Volumes/YOLLIEBLUES/JS.finalProject/question.json
Line Number 1, Column 1:

我使用 firefox 作为我的浏览器

"use strict";


let quizContainer = document.getElementById('quiz');
let resultContainer = document.getElementById('result');
let submitButton = document.getElementById('submit');

let myObj = "";
loadQuestions();

function loadQuestions() {
  let test = new XMLHttpRequest();
  test.open("Get", "question.json", true);
  test.onreadystatechange = function() {
    if (test.readyState == 4 && test.status == 200) {
      let myObj = JSON.parse(test.responseText);
      buildQuiz();
    }
  }
  test.send();
}

function buildQuiz() {
  for (var i in myObj) {
    console.log(myObj[i].question);
  }

}




//submitButton.addEventListener('click', showResults);

[
       {
            "title":"Superman is known as the world's greatest superhero. His alter-ego, Clark Kent, is a mild-mannered reporter for which newspaper?",
            "choices":[
                "The Daily Bugle",
                "The Gotham Gazette",
                "The Daily Planet",
                "The Central City Citizen"
            ],
            "correctAnswer":2
        },
        {
            "title":"John Constantine is a magician, demon-fighter, and all around do-gooder, but he's got one pretty serious vice. What is it?",
            "choices":[
                "Gambling",
                "Overeating",
                "Shoplifting",
                "Cigarettes"
            
            ],
            "correctAnswer":3
        },
        {
            "title": "She may be green, but she's got no reason to be jealous of anyone. In what universe is Guardian Gamora? ",
            "choices":[
                "Marvel",
                "Image",
                "Vertigo",
                "Top Shelf"
            ],
            "correctAnswer":0
        },
        {
            "title":"What is Peter Parker's middle name?",
            "choices":[
                "William",
                "Bartholomew",
                "Murdock",
                "Benjamin"
            ],
            "correctAnswer":3
        },
        {
            "title":"In honor of the Marvel's Infinity War comic book and movie coming out(You should really read the comic book soooo epic),Which villain possessed the Infinity Gems?",
            "choices":[
                "Galactus",
                "The Watchers",
                "Thanos",
                "Uatu"
            ],
            "correctAnswer":2
        },
        {
            "title":"Who paralyzed Barbara Gordon?",
            "choices":[
                "Two-Face",
                "ScareCrow",
                "The Joker (My husband to be)",
                "Solomon Grundy"
            ],
            "correctAnswer":2
        },
        {
            "title":"What is Batman Incorporated?",
            "choices":[
                "Army of Bat-Bot's",
                "Global crime-fighting organization"
            ],
            "correctAnswer":1
        },
        {
            "title":"Who is X-23?",
            "choices":[
                "New advanced Sentinel",
                "Wolverine's mutant clone"
            ],
            "correctAnswer":1
        },
        {
            "title":"Which book does Hermione steal from Dumbledore's office?",
            "choices":[
                "Magick Moste Evile",
                "The Tales of Beedle the Bard",
                "History of Magic",
                "Nature's Nobility: a Wizarding Genealogy"
            ],
            "correctAnswer":0
        },
        {
            "title":"Who disguised himself as Mad Eye Moody in the TheGoblet of Fire?",
            "choices":[
                "Barty Crouch Jr.",
                "Ernie McMillian",
                "Severus Snape",
                "Vincent Crabbe"
            ],
            "correctAnswer":0
        },{
            "title":"Han Solo's trusty blaster is a:?",
            "choices":[
                "D4-66",
                "BB-88",
                "DL-44"
            ],
            "correctAnswer":3
        },{
            "title":"Vader cuts off Luke's _____ hand?",
            "choices":[
                "right",
                "left",
                "both"
            ],
            "correctAnswer":0
        }
    ]

【问题讨论】:

  • 错误提示 json 的第 24 行有问题 "title":"I'm a warrior, an assassin. I don't dance." "She may be green, but she's got no reason to be jealous of anyone. In what universe is Guardian Gamora? ", 是的,对我来说看起来不对(检查你的报价 "
  • 好的,我现在修复它,我收到此错误 XML Parsing Error: syntax error Location: file:///Volumes/YOLLIEBLUES/JS.finalProject/question.json 第 1 行,第 1 列:
  • this.responseText 是什么?不应该是test.responseText吗?
  • 我也解决了这个问题,但我仍然收到该错误 XML Parsing Error: syntax error Location: file:///Volumes/YOLLIEBLUES/JS.finalProject/question.json 第 1 行,第 1 列
  • 我猜,但您是否从代码中删除了那些 **?您还应该检查 HTTP 状态响应代码:if ( test.readyState == 4 && test.status == 200 )

标签: javascript jquery json


【解决方案1】:

通过以下堆栈溢出帖子来转义值中的双引号。 Javascript Escape Double Quotes

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-18
    • 2021-11-11
    • 2013-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多