I have a json that contains 3 objects: question, tags, and choices.
[
{
"question" : {
"questionId" : 01,
"isActive" : 1
},
"tags" : ["tag1", "tag2"],
"choices" : [{
"choiceId" : 0,
"questionId" : 0
}, {
"choiceId" : 1,
"questionId" : 0
}
]
}
]
I currently am using GSON and this Extractor class with the intention of getting the details from the 3 different objects:
public class Extractor {
//question, tags, and choices are existing classes
Questions question;
List<Tags> tags;
List<Choice> choices;
//getters and setters
}
Extractor result = gson.fromJson(jsonString, Extractor.class);
//I want to see the question, tag, and choice parts from the json
System.out.println("Result" + result.getTags().get(0).getName() + result.getChoices().get(0).getChoiceId());
What am I doing wrong? How do I get the properties of question, tags, and choices separately? Also, how would I be able to iterate over a JSONlist that contains multiple questions, tags, and choices?