-1
我使用OkHttp 3.8.0使用Retrofit版本2.3.0。當我使用GET請求打我的api時,它返回200,但我無法訪問Version
模型中的元素。Retrofit Http給予api調用成功,但返回模型元素爲空
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;
}
}
我的更新接口:
public interface APIService {
@GET("apps/appType/ANDROID/version/{versionCode}")
Call<Version> getVersionByVersionCode(@Path("versionCode") int versionCode);
}
也許映射失敗,plzz發佈烏爾原始響應和版本 –
類也,把你的更新接口 –
@Roy請檢查我已經更新我的版本的類和接口 – Swapnil