无论何时与初始化整数一起使用,Retrofit都将返回null,而在直接使用整数数字进行调用时,则返回数据... 我正在使用@path访问WordPress-rest-api的数据
这是我的界面
public interface ImageDataApi {
String BASE_URL = "https://dwarkawala.com/index.php/wp-json//wp//v2//";
@GET("media/{Id}")
Call<Thumbnail> getImageData(
@Path("Id") int postId
);
class ImageFactory {
private static ImageDataApi service;
public static ImageDataApi getInstance() {
if (service == null) {
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASE_URL)
.build();
service = retrofit.create(ImageDataApi.class);
return service;
} else {
return service;
}
}
}
我这样打电话,它一直都返回null
int number = post.getId();
ImageDataApi.ImageFactory.getInstance().getImageData(number).enqueue(new Callback<Thumbnail>() {
@Override
public void onResponse(Call<Thumbnail> call, retrofit2.Response<Thumbnail> response) {
Log.d(TAG,String.valueOf(response.body()));
}
@Override
public void onFailure(Call<Thumbnail> call, Throwable t) {
}
});
但是当我直接这样打电话时,它就起作用了……
ImageDataApi.ImageFactory.getInstance().getImageData(3658).enqueue(new Callback<Thumbnail>() {
@Override
public void onResponse(Call<Thumbnail> call, retrofit2.Response<Thumbnail> response) {
Log.d(TAG,String.valueOf(response.body()));
}
@Override
public void onFailure(Call<Thumbnail> call, Throwable t) {
}
});
我不知道错误发生的地方,请帮忙...