【问题标题】:Issue with correct JSON syntax正确的 JSON 语法问题
【发布时间】:2022-11-26 01:28:42
【问题描述】:

我正在尝试在 javascript 应用程序中导入和解析 JSON。但是当我尝试这样做时,我的 javascript 代码没有运行。在开发人员工具上,我得到的错误是 Uncaught SyntaxError: Unexpected token ':' on line4 (the quiztitle line)。我不明白我的 JSON 的语法错误是什么。在下面。


{
    
    "quiztitle": "Quiz on the Baltic States",

    "quizarray":[

        { "questionblock1" :

        {
            "question":"What is the largest city in the Baltic States? ",
            "answer1": "Riga",
            "answer2": "Tallinn",
            "answer3": "Vilnius",
            "answer4": "Kaunas",
            "correctanswervar":"answer1",
            "correctanswer":"Riga"
        }

    }


    ]


}

【问题讨论】:

  • 您在问题中发布的对象没有问题。您的问题一定出在其他地方,请将代码发布到您使用它的地方。

标签: javascript arrays json import syntax


【解决方案1】:

我认为您的 JSON 文件格式不正确。我试着为你重新格式化它。如果这有效,请告诉我。

[
  {
    "quiztitle": "Quiz on the Baltic States",
    "quizarray": [
      {
        "question": "What is the largest city in the Baltic States? ",
        "answer1": "Riga",
        "answer2": "Tallinn",
        "answer3": "Vilnius",
        "answer4": "Kaunas",
        "correctanswervar": "answer1",
        "correctanswer": "Riga"
      }
    ]
  }
]

【讨论】:

    猜你喜欢
    • 2014-08-08
    • 2016-09-18
    • 2019-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多