Hello i have categories with answers data, e.g.:
- Europe: Germany, Austria, Hungary
- Asia: China, Japan, Cambodia
And I need to put it in json:
{
"correctAnswers": {
"category": {
"name" : "Europe",
"categoryAnswers": ["Germany", "Austria", "Hungary"]
}
}
}
How i can add the second category Asia with answers?
I understand that my question is very simple and my suggested variant may be not optimal but i am total new in Json and haven’t get the right answer in Google.
3
Answers
The data structure is all in the semantics of the data you’re describing. You keep using this word (in the question and comment(s)):
But your structure has this word:
That’s probably the difference you’re looking for. If
category
should represent plurality then I would imagine it should be an array:Which would then allow you to add more "category" objects to that array:
Ultimately it’s up to you and how you want to structure the data for the application. The data structure is essentially an endlessly nestable series of:
So if, semantically, the
correctAnswers
object should have a list ofcategory
objects, then semantically that list would be calledcategories
and would be an array. It’s really up to the semantics of the data you’re trying to describe in the structure.You can put something like this, if behind you want to gather it in some list of objects :