我正在使用OkTttp 3.8.0的Retrofit版本2.3.0。当我使用GET请求点击我的api时,它返回200作为结果,但我无法访问Version
模型中的元素。
APIService apiService = APIClient.getAPIService();
Call<Version> call = apiService.getVersionByVersionCode(BuildConfig.VERSION_CODE);
call.enqueue(new Callback<Version>() {
@Override
public void onResponse(Call<Version> call, Response<Version> response) {
Version result = response.body();
Log.e("TAG", "OnResponse " + result.toString());
}
@Override
public void onFailure(Call<Version> call, Throwable t) {
Log.e("TAG", "Failure ");
}
});
这是我的Version
课程,当我访问实例的versionName
或version
元素时,我得到null
:
package com.actovoice.model;
import com.google.gson.annotations.SerializedName;
public class Version {
@SerializedName("upgrade") int upgrade;
@SerializedName("versionName") String versionName;
@SerializedName("version") String version;
public int getUpgrade() {
return upgrade;
}
public void setUpgrade(int upgrade) {
this.upgrade = upgrade;
}
public String getVersionName() {
return versionName;
}
public void setVersionName(String versionName) {
this.versionName = versionName;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}
My Retrofit界面:
public interface APIService {
@GET("apps/appType/ANDROID/version/{versionCode}")
Call<Version> getVersionByVersionCode(@Path("versionCode") int versionCode);
}
答案 0 :(得分:0)
尝试将Scalar Converter添加到您的Retrofit实例中,如下所示:
.addConverterFactory(ScalarsConverterFactory.create())