我最近开始使用Retrofit.我不太了解它.我搜索了这个问题,没有答案解决我的问题.
这是JSON响应
{
"results": [
{
"description_eng": "This is second time testing",
"img_url": "-",
"title_eng": "Second test"
},
{
"description_eng": "Hello 1 2 3, I am testing.",
"img_url": "https://fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-xpa1/t31.0-8/s720x720/10838273_816509855058935_6428556113200361121_o.jpg",
"title_eng": "Test"
}
]
}
这是Feed类
public class Feed {
public List<Results> results;
class Results{
String description_eng,img_url,title_eng;
}
}
这是界面
public interface GetApi {
@GET("/api.json")
public void getData(Callback<List<Feed>> response);
}
我得到了json_illegal_syntax异常.
解决方法:
这就是我通过创建空构造函数来解决这个问题的方法.
Feed.class
public class Feed{
private List<Result> results;
public Feed(){}
public List<Result> getFeed(){
return this.results;
}
public void setFeed(List<Result> results) {
this.results = results;
}
}
Result.class
public class Result{
private String description_eng;
private String img_url;
private String title_eng;
public Result(){}
//getters and setters
}
GetApi.class
public interface GetApi {
@GET("/api.json")
public void getData(Callback<Feed> response);
}