我得到了api的回应 我必须得到这样的反应:
@SerializedName("AllQuestions")
public List<AllQuestions> AllQuestions;
我有AllQuestion数组,但现在如何进入pojo类中的多列表数组
"AllQuestions": [
[
{
"QuestionID": "1",
"QuestionText": "What was the name of your elementary/primary school?"
},
{
"QuestionID": "2",
"QuestionText": "What was your childhood nickname?"
}
],
[
{
"QuestionID": "11",
"QuestionText": "What was your favorite sport in high school?"
},
{
"QuestionID": "12",
"QuestionText": "What was the name of the hospital where you born?"
}
],
[
{
"QuestionID": "21",
"QuestionText": "Where were you when you had your first kiss?"
},
{
"QuestionID": "22",
"QuestionText": "What are the last 4 digits of your driving license?"
},
]
]
AllQuestion.java(POJO Class)
@SerializedName("QuestionID")
public String QuestionID;
@SerializedName("QuestionText")
public String QuestionText;
答案 0 :(得分:1)
第1步:访问http://www.jsonschema2pojo.org/
第2步:复制您的回复并将其粘贴到那里并输入包和类名
步骤3:选择目标语言为Java
步骤4:将源类型标记为Json
步骤5:将注释样式标记为Gson
第6步:预览
第7步:将这些类复制到您的应用包
答案 1 :(得分:0)
<强> Question.java 强>
public class Question {
@SerializedName("QuestionID")
public String QuestionID;
@SerializedName("QuestionText")
public String QuestionText;
}
<强> AllQuestion.java 强>
public class AllQuestion{
public List<Question> questions; // no need of serialization as inner array
doesn't have any keys
}
然后使用下面的
@SerializedName("AllQuestions")
public List<AllQuestions> AllQuestions;