Loszek Loszek - 1 month ago 10
Java Question

How to write a json file which contains two arraylists<String>

I have to read from JSON file to two arraylist which one contains question and second contains answer but I don't know how to write that file. It's going to be a simple quiz. Can anyone give me an example

Answer

Maybe something like this?

{
   "questions":
   [
        "What is the capital of France?",
        "What is the answer to everything?"
   ],
   "answers":
   [
        "Paris", 
        "forty-two"
   ]
}

An alternative way would bundling question-answer-pairs:

[
   {
     "q": "What is the capital of France?",
     "a": "Paris" 
   },
   {
     "q": "What is the answer to everything?",
     "a": "42" 
   }
]

It depends on your application which way is more convenient and natural.