如何通过类似的键值将改造pojo的响应分组?

时间:2019-07-11 07:34:56

标签: java android json retrofit pojo

JSON响应:

{
    "error": "false",
    "data": [
        {
            "id": "2596",
            "question": "test",
            "answer": "c",
            "subject_name": "Physics"
        },
        {
            "id": "2595",
            "question": "what is chemistry?",
            "answer": "c",
            "subject_name": "Chemistry"
        },
        {
            "id": "2594",
            "question": "what is physics?",
            "answer": "a",
            "subject_name": "Physics"
        }
    ]
}

我想按“主题名称”对响应进行分组

我的POJO课程:

public class Question {

    @SerializedName("id")
    @Expose
    private String id;
    @SerializedName("question")
    @Expose
    @SerializedName("answer")
    @Expose
    private String answer;
    @SerializedName("subject_name")
    @Expose
    private String subject_name;    
    public String getSubject_name() {
        return subject_name;
    }
    public void setSubject_name(String subject_name) {
        this.subject_name = subject_name;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getQuestion() {
        return question;
    }
    public void setQuestion(String question) {
        this.question = question;
    }
    public String getAnswer() {
        return answer;
    }
    public void setAnswer(String answer) {
        this.answer = answer;
    }
    public String getLevel() {
        return level;
    }
  }

0 个答案:

没有答案