当我尝试使用 Retrofit2 + Rxjava 从 api 获取数据时,我开始使用 Retrofit:
API服务:
@GET("news/get_comments/{newsid}/{count}/{offset}")
Observable<ResultResponse<CommentList>> getComment(@Header("api_key") String key, @Path("newsid") String newsid, @Path("count")String count, @Path("offset")String offset);
public void getComment(String item_id, int pageNow) {
int offset = (pageNow - 1) * 10;
Log.i("commentlist", offset+"");
Log.i("commentlist",pageNow+"");
addSubscription(AppClient.getApiService().getComment(ApiService.KEY,item_id,"10",offset+""), new SubscriberCallBack<CommentList>() {
@Override
protected void onSuccess(CommentList response) {
Logger.i("commentist",response.toString());
mvpView.onGetCommentSuccess(response);
}
});
}
GSON 抛出错误:com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 41 path $.data
最佳答案
这是因为您的响应以 [] 而不是 {} 开头,实际上您得到的是 jsonarray 而不是 jsonobject
关于java - Retrofit2获取数据GSON抛出 "Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 41 path $.data",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44975973/