I reading this Json , I have created the classes as below , My challange is how to read MultipleChoices to its model class from the response
[
{
"Id": "1",
"Question": "Suggest areas of improvement in the running of coretec with regards to information technology",
"HasMultipleChoices": "0",
"MultipleChoices": []
},
{
"Id": "2",
"Question": "Did you enjoy last year's team building and what suggestions would you have for tbhis year's teambuilding?",
"HasMultipleChoices": "0",
"MultipleChoices": []
},
{
"Id": "3",
"Question": "Do you think the support you get from management in carrying out your tasks is sufficient?",
"HasMultipleChoices": "1",
"MultipleChoices": [
{
"Id": "1",
"MultipleChoice": "Yes"
},
{
"Id": "2",
"MultipleChoice": "No"
}
]
}
]
This is my mulitple class
public class MultipleChoice {
public String id;
public String multipleChoice;
public MultipleChoice(String id, String multipleChoice) {
super();
this.id = id;
this.multipleChoice = multipleChoice;
}
}
This is my Question Class model
public class Questions {
public int id;
public String Questions;
public String HasMultipleChoices;
public String MultipleChoices;
public List<MultipleChoice> multipleChoices = null;
public Questions(int id, String Questions ,String HasMultipleChoices, List<MultipleChoice> multipleChoices) {
this.Questions = Questions;
this.id = id;
this.HasMultipleChoices = HasMultipleChoices;
this.multipleChoices = multipleChoices;
}
}
and this this is how am reading the json through volley
public void onResponse(String response) {
// Do something with the response
progressbar.setVisibility(View.GONE);
JSONArray jsonarray;
List<Questions> list = new ArrayList<>();
try {
jsonarray = new JSONArray(response);
for (int i=0; i<jsonarray.length(); i++)
{
// String ProductName,Price,Category,Description,Brand,Image1,Image2,Image3,Image4,Image5;
JSONObject jobObject =jsonarray.getJSONObject(i);
Questions item= new Questions(jobObject.getInt("Id"),jobObject.getString("Question")
,jobObject.getString("HasMultipleChoices"),"WHAT SHOULD I DO HERE TO HAVE A LIST OF MULITPLECHOICES?");
list.add(item);
}
updateList(list);
} catch (JSONException e) {
e.printStackTrace();
}
}