我得到这个错误:com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:路径$.data的第1行第10列应为开始_OBJECT,但实际上是BEGIN_ARRAY
https://kitsu.io/api/edge/anime
()创建一个新的服务示例;
public void makeApiCall() {
Call<Animes> call = retroService.getAnimes();
call.enqueue(new Callback<Animes>() {
@Override
public void onResponse(Call<Animes> call, Response<Animes> response) {
Log.d("Result", response.body().getData().getAttributes().getCanonicalTitle());
}
@Override
public void onFailure(Call<Animes> call, Throwable t) {
}
});
}
@GET(“动漫”)
```Call<Animes> getAnimes(); ```
我的POJO课程:
@Expose
private Data data;
/**
* No args constructor for use in serialization
*
*/
public Animes() {
}
/**
*
* @param data
*/
public Animes(Data data) {
super();
this.data = data;
}
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
public class Data {
@SerializedName("id")
@Expose
private String id;
@SerializedName("type")
@Expose
private String type;
@SerializedName("attributes")
@Expose
private Attributes attributes;
//With getter and setters and constructor
public class Attributes {
@SerializedName("synopsis")
@Expose
private String synopsis;
@SerializedName("canonicalTitle")
@Expose
private String canonicalTitle;
@SerializedName("startDate")
@Expose
private String startDate;
@SerializedName("endDate")
@Expose
private String endDate;
@SerializedName("ratingRank")
@Expose
private Integer ratingRank;
@SerializedName("status")
@Expose
private String status;
@SerializedName("episodeCount")
@Expose
private Integer episodeCount;
@SerializedName("youtubeVideoId")
@Expose
private String youtubeVideoId;
//With getter and setters and constructor
1条答案
按热度按时间nqwrtyyt1#
基本上,
Expected BEGIN_OBJECT but was BEGIN_ARRAY
意味着您试图解析单个对象(Animes
),而JSON中没有单个对象,它是一个数组(根)我不知道你的
RetroInstance
和RetroService
是如何工作的,但是这个:应该是