Topic was automatically imported from the old Question2Answer platform.
Asked By
rogerdv
Need some help to find the right syntax for json, what I have now is this:
[
{
“question”: “La II Guerra Mundial se inició el:”,
“topic”: “Historia”,
“choices”: [
[“answer”:“25 de Agosto de 1941”,“correct”:“no”],
[“answer”:“3 de Julio de 1939”,“correct”:“no”],
[“answer”:“12 de abril de 1945”,“correct”:“no”],
[“answer”: “1 de septiembre de 1939”,“correct”:“yes”]
]
}, **** many other questions
]
But I get an error saying a , is missing at line 5. Whats the correct syntax? I need to load this as a list of questions, to randomly choose one. Also, the answers must be an array, to randomize them before displaying.
Those items with answer and correct properties should be JSON objects, not JSON arrays. Here’s your JSON, with a few adjustments. I’ve also replicated the first question into question #2 to show how multiple array elements could look:
[
{
"question": "La II Guerra Mundial se inició el:",
"topic": "Historia",
"choices": [
{
"answer": "25 de Agosto de 1941",
"correct": "no"
},
{
"answer": "3 de Julio de 1939",
"correct": "no"
},
{
"answer": "12 de abril de 1945",
"correct": "no"
},
{
"answer": "1 de septiembre de 1939",
"correct": "yes"
}
]
},
{
"question": "La II Guerra Mundial se inició el:",
"topic": "Historia",
"choices": [
{
"answer": "25 de Agosto de 1941",
"correct": "no"
},
{
"answer": "3 de Julio de 1939",
"correct": "no"
},
{
"answer": "12 de abril de 1945",
"correct": "no"
},
{
"answer": "1 de septiembre de 1939",
"correct": "yes"
}
]
}
]
Whats the difference between arrays and objects? Im more familiar with XML and this is my first experience with JSON.
rogerdv | 2020-03-06 20:16
There are much better resources online for understanding the basics of JSON than any answer I could provide here. I’d suggest some quick Google searchs.