当前位置: 首页 > 知识库问答 >
问题:

应为BEGIN_OBJECT,但在第1行第74列路径$.data处为BEGIN_ARRAY

骆利
2023-03-14

我使用的是MVVMAndroid架构组件+改型结构。

答复:

{
"statuscode": 0,
"statusmessage": "",
"data": {
    "userdetails": {
        "id": "3",
        "name": "xxx",
        "mobile": "123456789",
        "username": "xxx",
        "password": "xxx",
        "createdate": "2019-08-14 16:51:22",
        "updatedate": "2019-08-14 16:51:22",
        "active": "Y",
        "userdeviceid": 2
    },
    "contacttypes": [
        {
            "id": "1",
            "name": "xxx",
            "active": "Y"
        },
        {
            "id": "5",
            "name": "xxx",
            "active": "Y"
        },
        {
            "id": "2",
            "name": "xxx",
            "active": "Y"
        },
        {
            "id": "4",
            "name": "xxx",
            "active": "Y"
        },
        {
            "id": "3",
            "name": "xxx",
            "active": "Y"
        }
    ]
}
}

现在这些是我的课。

public class APIResponse {

@SerializedName("statuscode")
private int statuscode;

@SerializedName("statusmessage")
private String statusmessage;

@SerializedName("data")
DATAModel dataModel;

public int getStatuscode() {
    return statuscode;
}

public void setStatuscode(int statuscode) {
    this.statuscode = statuscode;
}

public String getStatusmessage() {
    return statusmessage;
}

public void setStatusmessage(String statusmessage) {
    this.statusmessage = statusmessage;
}

public DATAModel getDataModel() {
    return dataModel;
}

public void setDataModel(DATAModel dataModel) {
    this.dataModel = dataModel;
}
}
public class DATAModel {

@SerializedName("userdetails")
Userdetails userdetails;

@SerializedName("contacttypes")
List<ContactTypes> contactTypes;

public Userdetails getUserdetails() {
    return userdetails;
}

public void setUserdetails(Userdetails userdetails) {
    this.userdetails = userdetails;
}


public List<ContactTypes> getContactTypes() {
    return contactTypes;
}

public void setContactTypes(List<ContactTypes> contactTypes) {
    this.contactTypes = contactTypes;
}
}
public class Userdetails implements Serializable {

@SerializedName("id")
private String userId;

@SerializedName("name")
private String name;

@SerializedName("mobile")
private String mobile;

@SerializedName("username")
private String username;

@SerializedName("password")
private String password;

@SerializedName("createdate")
private String createdate;

@SerializedName("updatedate")
private String updatedate;

@SerializedName("active")
private String active;

@SerializedName("userdeviceid")
private String userdeviceid;


public String getUserdeviceid() {
    return userdeviceid;
}

public void setUserdeviceid(String userdeviceid) {
    this.userdeviceid = userdeviceid;
}

public String getUserId() {
    return userId;
}

public void setUserId(String userId) {
    this.userId = userId;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getMobile() {
    return mobile;
}

public void setMobile(String mobile) {
    this.mobile = mobile;
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getCreatedate() {
    return createdate;
}

public void setCreatedate(String createdate) {
    this.createdate = createdate;
}

public String getUpdatedate() {
    return updatedate;
}

public void setUpdatedate(String updatedate) {
    this.updatedate = updatedate;
}

public String getActive() {
    return active;
}

public void setActive(String active) {
    this.active = active;
}
}
public class ContactTypes implements Serializable {

@SerializedName("id")
private String contactId;

@SerializedName("name")
private String name;

@SerializedName("active")
private String active;

public String getContactId() {
    return contactId;
}

public void setContactId(String contactId) {
    this.contactId = contactId;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getActive() {
    return active;
}

public void setActive(String active) {
    this.active = active;
}
}

虽然每次我都失败了。消息应为BEGIN_OBJECT,但在第1行第74列path$.data处为BEGIN_ARRAY

高级帮助将非常感谢!

共有1个答案

后焕
2023-03-14

当您试图将1 column 74 path$.data处的响应解析为对象时,会出现此错误,该对象类似于“data”:{}但API的实际响应是“data”:[{},{},...]

我相信这就是错误发生的地方

@SerializedName("data")
DATAModel dataModel;

有关更多信息,请查看此答案

 类似资料: