First of all your raw response is incorrect. If you paste your response in http://jsonlint.com/
You will get parse error in line 12. Even jsonschema2pojo is also displaying error in your raw response. First of all modify it like
{
"paper": [
{
"que": {
"qid": "1",
"question": "????????????????"
},
"ans": [
{
"id": "1",
"answer": "uiuyiyityu"
},
{
"id": "2",
"answer": "ytuyutyuty"
},
{
"id": "3",
"answer": "retre retret"
},
{
"id": "4",
"answer": "rtretret"
}
]
}
]
}
Then make POJO on jsonschema2pojo tool. The tool will create four different POJOs like following:
import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@Generated("org.jsonschema2pojo")
public class An {
@SerializedName("id")
@Expose
private String id;
@SerializedName("answer")
@Expose
private String answer;
/**
*
* @return
* The id
*/
public String getId() {
return id;
}
/**
*
* @param id
* The id
*/
public void setId(String id) {
this.id = id;
}
/**
*
* @return
* The answer
*/
public String getAnswer() {
return answer;
}
/**
*
* @param answer
* The answer
*/
public void setAnswer(String answer) {
this.answer = answer;
}
}
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@Generated("org.jsonschema2pojo")
public class Paper {
@SerializedName("paper")
@Expose
private List<Paper_> paper = new ArrayList<Paper_>();
/**
*
* @return
* The paper
*/
public List<Paper_> getPaper() {
return paper;
}
/**
*
* @param paper
* The paper
*/
public void setPaper(List<Paper_> paper) {
this.paper = paper;
}
}
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@Generated("org.jsonschema2pojo")
public class Paper_ {
@SerializedName("que")
@Expose
private Que que;
@SerializedName("ans")
@Expose
private List<An> ans = new ArrayList<An>();
/**
*
* @return
* The que
*/
public Que getQue() {
return que;
}
/**
*
* @param que
* The que
*/
public void setQue(Que que) {
this.que = que;
}
/**
*
* @return
* The ans
*/
public List<An> getAns() {
return ans;
}
/**
*
* @param ans
* The ans
*/
public void setAns(List<An> ans) {
this.ans = ans;
}
}
import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@Generated("org.jsonschema2pojo")
public class Que {
@SerializedName("qid")
@Expose
private String qid;
@SerializedName("question")
@Expose
private String question;
/**
*
* @return
* The qid
*/
public String getQid() {
return qid;
}
/**
*
* @param qid
* The qid
*/
public void setQid(String qid) {
this.qid = qid;
}
/**
*
* @return
* The question
*/
public String getQuestion() {
return question;
}
/**
*
* @param question
* The question
*/
public void setQuestion(String question) {
this.question = question;
}
}
Now you can get your qid and id very easily by calling methods of your POJOs. Use this code block for getting qid and id.
Paper paper = new Paper();
List<Paper_> papers = paper.getPaper();
for(Paper_ paper_ : papers){
int qid = paper_.getQue().getQid();
List<An> answers = paper_.getAns();
for(An answer : answers){
int ansId = answer.getId();
}
}
Hope it will work.