JSON“预期的字符串未定义”错误

时间:2019-04-22 17:47:38

标签: json

我在说这个错误:

Parse error on line 1:
{   quizzes:{    quiz_1
----^
Expecting 'STRING', '}', got 'undefined'

我遵循了一个教程,它是一行一行的,但是仍然无法正常工作。任何帮助,将不胜感激。

我是JSON的新手,并且尝试了我在Google上看到的所有内容。我的代码不包含任何反引号。

{ 
  quizzes:{
    quiz_1: {
      "QuizName": "Addition"
    },
    quiz_2: {
      "QuizName": "Subtraction"
    },
    quiz_3: {
      "QuizName": "Dividing"
    }
  },
  questions:{
    quiz_1: {
      question_1:{ 
        "answer" : 4,
        "choice1" : 1,
        "choice2" : 2,
        "choice3" : 3,
        "choice4" : 4,
        "question" : "What is 2+2"
      },
    },
    question_2:{
      quiz_2: {
        "answer" : 4,
        "choice1" : 1,
        "choice2" : 2,
        "choice3" : 3,
        "choice4" : 4,
        "question" : "What is 2+2"
      },
    },
    question_3:{
      quiz_3: {
        "answer" : 4,
        "choice1" : 1,
        "choice2" : 2,
        "choice3" : 3,
        "choice4" : 4,
        "question" : "What is 2+2"
      }
    }
  }
}

1 个答案:

答案 0 :(得分:1)

您的JSON应该看起来像这样。

请注意,测验在双引号内。将其视为双引号键。

question_1的对象后面有一个逗号。删除它。您可以使用https://jsonlint.com/来验证JSON是否正确。

{ 
  "quizzes":{
    "quiz_1": {
      "QuizName": "Addition"
    },
    "quiz_2": {
      "QuizName": "Subtraction"
    },
    "quiz_3": {
      "QuizName": "Dividing"
    }
  },
  "questions":{
    "quiz_1": {
      "question_1":{ 
        "answer" : 4,
        "choice1" : 1,
        "choice2" : 2,
        "choice3" : 3,
        "choice4" : 4,
        "question" : "What is 2+2"
      }
    },
    "question_2":{
      "quiz_2": {
        "answer" : 4,
        "choice1" : 1,
        "choice2" : 2,
        "choice3" : 3,
        "choice4" : 4,
        "question" : "What is 2+2"
      }
    },
    "question_3":{
      "quiz_3": {
        "answer" : 4,
        "choice1" : 1,
        "choice2" : 2,
        "choice3" : 3,
        "choice4" : 4,
        "question" : "What is 2+2"
      }
    }
  }
}