我已经阅读了很多关于同一错误的答案,但没有任何帮助我。
这里我尝试将Json解析为我的数据类并收到错误:
ErrorResponse bodyResponse = App.getGson().fromJson(responseString, ErrorResponse.class);
错误是:BEGIN_OBJECT但是STRING
这是我的回复字符串:
'{"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;
}}
有什么问题?
我的详细信息类代码(我减少了get / set以发布它)
public class Details {
public String code;
public String msg;
public Attachment attachment;
public String message;
public String description;
public Details() {
}
}
提前致谢。
答案 0 :(得分:0)
试试这个
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;
}
}
}