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

json应为BEGIN_OBJECT,但为

钱青青
2023-03-14

我已经读过许多关于同一错误的答案,但没有任何帮助。

ErrorResponse bodyResponse = App.getGson().fromJson(responseString, ErrorResponse.class);
'{"title":"AccessCheckException","details":{"message":"User doesn't have authorized access."}}'
public class ErrorResponse {
    public String title;
    public Details details;

    public ErrorResponse() {
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Details getDetails() {
        return details;
    }

    public void setDetails(Details details) {
        this.details = details;
    }}
public class Details {
public String code;
public String msg;
public Attachment attachment;
public String message;
public String description;

public Details() {
}

提前道谢。

共有1个答案

须旭
2023-03-14

试试这个

errorresponse.java与您的json不匹配

    public class ErrorResponse {

    @SerializedName("title")
    @Expose
    private String title;
    @SerializedName("details")
    @Expose
    private Details details;

    public String getTitle() {
    return title;
    }

    public void setTitle(String title) {
    this.title = title;
    }

    public Details getDetails() {
    return details;
    }

    public void setDetails(Details details) {
    this.details = details;
    }

    public class Details {

    @SerializedName("message")
    @Expose
    private String message;

    public String getMessage() {
    return message;
    }

    public void setMessage(String message) {
    this.message = message;
    }

    }

    }
 类似资料: