以下json数据的问题

时间:2011-05-23 19:22:17

标签: json

我正在试图找出以下json数据的错误,我正在使用http://jsonlint.com/来验证它是否会失败;

Parse error on line 9:
...                    "Question 2" : [   
-----------------------^
Expecting 'EOF', '}', ',', ']'

我的代码;

{ "questions" : {
                    "Question 1" : [
                    { "Q" :"Question" },
                    { "A" : "Answer A"  },
                    { "B" : "Answer B" },
                    { "C" : "Answer C" },
                    { "D" : "Answer D" },
                    { "Answer" : "C" }
                    ] 
                    "Question 2" : [
                    { "Q" :"Question" },
                    { "A" : "Answer A"  },
                    { "B" : "Answer B" },
                    { "C" : "Answer C" },
                    { "D" : "Answer D" },
                    { "Answer" : "C" }
                    ] 
}
                    }";

4 个答案:

答案 0 :(得分:5)

你忘记了一个逗号!

{ "questions" : {
                "Question 1" : [
                { "Q" :"Question" },
                { "A" : "Answer A"  },
                { "B" : "Answer B" },
                { "C" : "Answer C" },
                { "D" : "Answer D" },
                { "Answer" : "C" }
                ],
                "Question 2" : [
                { "Q" :"Question" },
                { "A" : "Answer A"  },
                { "B" : "Answer B" },
                { "C" : "Answer C" },
                { "D" : "Answer D" },
                { "Answer" : "C" }
                ] 
}}

答案 1 :(得分:2)

缺少问题键之间的逗号。

{ "questions" : {
                    "Question 1" : [
                    { "Q" :"Question" },
                    { "A" : "Answer A"  },
                    { "B" : "Answer B" },
                    { "C" : "Answer C" },
                    { "D" : "Answer D" },
                    { "Answer" : "C" }
                    ],
                    "Question 2" : [
                    { "Q" :"Question" },
                    { "A" : "Answer A"  },
                    { "B" : "Answer B" },
                    { "C" : "Answer C" },
                    { "D" : "Answer D" },
                    { "Answer" : "C" }
                    ] 
}
                    }

答案 2 :(得分:2)

数组关闭后你错过了一个逗号。

JSON = { 
  "questions" : {
      "Question 1" : [
          { "Q" :"Question" },
          { "A" : "Answer A"  },
          { "B" : "Answer B" },
          { "C" : "Answer C" },
          { "D" : "Answer D" },
          { "Answer" : "C" }
      ],// end of Question 1 "this is where you'r missing the comma"
      "Question 2" : [
          { "Q" :"Question" },
          { "A" : "Answer A"  },
          { "B" : "Answer B" },
          { "C" : "Answer C" },
          { "D" : "Answer D" },
          { "Answer" : "C" }
      ] // end of Question 2
  }//end of questions object
}";

答案 3 :(得分:0)

期待&#39; EOF&#39;,&#39;}&#39;,&#39; ,&#39;,&#39;]&#39; < /强>

在一系列问题之间,你错过了COMMA&#34;问题1&#34;正如其他人的回答。如果你正在使用JERSEY,那么让JSONSON等REST提供者完成Plain Object to JSON字符串映射。否则,请使用其他API进行映射。

验证清楚地回答了它,但是缺少了逗号的确切位置。经常遇到的错误是缺少{brace for object,[括号代表数组,或者(逗号)分隔元素数组)。