Reputation: 2513
I'm trying to figure out whats wrong with the following json data, i'm currently using http://jsonlint.com/ to validate it which keeps failing with;
Parse error on line 9:
... "Question 2" : [
-----------------------^
Expecting 'EOF', '}', ',', ']'
My code;
{ "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" }
]
}
}";
Upvotes: 0
Views: 6498
Reputation: 171
you're missing a comma after the array closes.
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
}";
Upvotes: 2
Reputation: 1763
Expecting 'EOF', '}', ',
', ']'
Between array of Questions, You missed COMMA after "Question 1" as answered by others. Let Plain Object to JSON string mapping be done by REST providers like JAKSON if you're using JERSEY. Otherwise, use other APIs for mapping.
The validation answers it clearly, however where exactly the comma is missing. The very common mistakes experienced are either missing { brace for object, [ bracket for representing arrays or ,(comma) for delimiting array of elements.
Upvotes: 0
Reputation: 1977
You've forgot a comma!
{ "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" }
]
}}
Upvotes: 5
Reputation: 73011
Missing the comma between your Question keys.
{ "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" }
]
}
}
Upvotes: 2