I made a function : input ID card numbers, click the submit button, then get the basic info of the ID card.
the MODEL I used:
public class IdCardInfo {
private int errNum;
private String retMsg;
private RetDataBean retData;
public int getErrNum() {
return errNum;
}
public void setErrNum(int errNum) {
this.errNum = errNum;
}
public String getRetMsg() {
return retMsg;
}
public void setRetMsg(String retMsg) {
this.retMsg = retMsg;
}
public RetDataBean getRetData() {
return retData;
}
public void setRetData(RetDataBean retData) {
this.retData = retData;
}
public static class RetDataBean {
private String sex;
private String birthday;
private String address;
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
}
the retrofit interface I used:
@GET("apistore/idservice/id")
Observable<IdCardInfo> getIdCardInfo(@Query("id") String id);
when I input the correct ID card numbers, everything works well. the returned result is:
{
"errNum": 0,
"retMsg": "success",
"retData": {
"sex": "M",
"birthday": "1987-04-20",
"address": "some place"
}
}
Everything works well.
However when I input a incorrect ID card numbers, the bad things happens:
Caused by: java.lang.IllegalStateException:
Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 86 path $.retData
the returned result is:
{
"errNum": -1,
"retMsg": "Incorrect ID card number!",
"retData": [ ]
}
How could I fix the bugs?