I'm working to create a web service to return one nested json like this:
{
"questionaire": {
"idSection": 1,
"sectionName": "Section Test 1",
"questions": {
"text": {
"idQuestion": 1,
"statement": "Question statement",
"kindQuestion": "boolean",
"availableAnswers": {
"idAnswer": 1,
"stringAnswer": "answer 1"
}
}
}
},
"idSection": 1,
"sectionName": "Section Test 1",
"questions": {
"text": {
"idQuestion": 1,
"statement": "Question statement",
"kindQuestion": "boolean",
"availableAnswers": {
"idAnswer": 1,
"stringAnswer": "answer 1"
}
}
}
}
I'm not 100% sure if the structure I wrote is correct, the idea is: I got sections, which contains questions and every answer related to question is from one kind (boolean, numeric, select) and has her own answers. All this data I have it on a database, now I have to get the sections and all the relative information like: section > questions > type answer > available answers.
This is what I'm trying to do but it doesn't work appropriately I don't know how to nest the questions relative to the section and the answers inside the questions and go on.
// ques is a JSONArray
sections = resultset from database;
// While loop for every section
while(sections.next()){
// Here I start to create the json
jsonD.put("sectionID", sections.getInt("id"));
jsonD.put("sectionName", sections.getString("sectionName"));
questions = resultset from database, contains the questions for every section
// Recupera preguntes vinculades a la seccio
while(questions.next()){
ques.put("idQuestion", id);
ques.put("statement", statement);
...
}
}
On this point my code does not create the nested json appropriately