使用翻新2,但是期望BEGIN_OBJECT但在第1行第1列路径$ STRING [英] Using Retrofit 2 but, have Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
本文介绍了使用翻新2,但是期望BEGIN_OBJECT但在第1行第1列路径$ STRING的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我进行请求使用Retrofit 2从Flickr获取照片.
I make request get photos from Flickr, using Retrofit 2.
我创建了一个用于解析它的类:
I create a class for parsing it:
public class FlickrResult {
@SerializedName("photos")
@Expose
private FlickrPhotos photos;
@SerializedName("stat")
@Expose
private String stat;
public FlickrPhotos getPhotos() {
return photos;
}
public class FlickrPhotos {
@SerializedName("page")
@Expose
private int page;
@SerializedName("pages")
@Expose
private String pages;
@SerializedName("perpage")
@Expose
private int perpage;
@SerializedName("total")
@Expose
private String total;
@SerializedName("photo")
@Expose
private ArrayList<FlickrPhoto> photo;
public ArrayList<FlickrPhoto> getPhoto() {
return photo;
}
public class FlickrPhoto {
@SerializedName("id")
@Expose
private String id;
@SerializedName("owner")
@Expose
private String owner;
@SerializedName("secret")
@Expose
private String secret;
@SerializedName("server")
@Expose
private String server;
@SerializedName("farm")
@Expose
private int farm;
@SerializedName("title")
@Expose
private String title;
@SerializedName("ispublic")
@Expose
private int ispublic;
@SerializedName("isfriend")
@Expose
private int isfriend;
@SerializedName("isfamily")
@Expose
private int isfamily;
public String getTitle() {
return title;
}
}
}
}
我的构建请求是:
static {
gson = new GsonBuilder()
.setLenient()
.create();
}
@NonNull
private static Retrofit buildRetrofit() {
Log.i(TAG, "onBuildRetrofitApiFactory");
return new Retrofit.Builder()
.baseUrl("https://api.flickr.com/services/")
.client(getClient())
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
改造界面
@GET("rest")
Call<FlickrResult> getPhotos(@Query("method") String method,
@Query("api_key") String key,
@Query("format") String format,
@Query ("nojsoncallbac") String nojsoncallbac
);
我负责的是成功,但解析存在问题.有经验:
Me responsable is success, but problem in parsing. Have exeption:
拜托,我需要你的帮助!
Please guys, i need you help!
推荐答案
您的翻新界面错误.
参数"nojsoncallbac"不正确,应为"nojsoncallback".
The paremeter "nojsoncallbac" is incorrect and should be "nojsoncallback".
此参数错误导致API在响应中返回不同的格式
This incorrect parameter causes the API to return a different format on the response
jsonFlickrApi({
"photos": {
"page": 1,
"pages": 10,
"perpage": 100,
"total": 1000,
"photo": [
...
]
}
})
这篇关于使用翻新2,但是期望BEGIN_OBJECT但在第1行第1列路径$ STRING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文