Hey everyone,
I'm currently stuck with a JSON problem I can't solve. I want to add a new element into this existing JSON file, but I am struggling to recreate the JSON structure within C3.
It's for a quiz game, the JSON file stores all the questions and I am trying to create a question editor, where I can enter new question and add them to the JSON file.
Here's what I did so far:
1. I created a Dictionary with the keys:
id, question, answersArray, wrongAnswersArray, hint
2. Grabbed some data from Input Fields and added to the Dictionary
3. Set some data for the arrays and added the array.AsJSON as Value in the Dictionary
My Template JSON
{
"questions": [
{
"id": "0",
"question": "What is that?",
"answersArray": [
"answer1",
"answer2"
],
"wrongAnswersArray": [
"wrongAnswer1",
"wrongAnswer2"
],
"hint": "Lorem ipsum"
},
{
"id": "1",
"question": "What is this?",
"answersArray": [
"answer1",
"answer2"
],
"wrongAnswersArray": [
"wrongAnswer1",
"wrongAnswer2"
],
"hint": "Lorem ipsum"
},
{
"id": "2",
"question": "What is not true?",
"answersArray": [
"answer1",
"answer2"
],
"wrongAnswersArray": [
"wrongAnswer1",
"wrongAnswer2"
],
"hint": "Lorem ipsum"
}
]
}
C3 Output when I log the Dictionary.AsJSON
{
"c2dictionary": true,
"data": {
"id": 123,
"question": "What is red?",
"answersArray": "{\"c2array\":true,\"size\":[1,1,1],\"data\":[[[\"Fire\"]]]}",
"wrongAnswersArray": "{\"c2array\":true,\"size\":[3,1,1],\"data\":[[[\"Sea\"]],[[\"Honey\"]],[[\"Cloud\"]]]}",
"hint": "It is hot."
}
}