2017-05-16 15 views
-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類,當我訪問一個實例的versionNameversion元素,我得到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); 

} 
+0

也許映射失敗,plzz發佈烏爾原始響應和版本 –

+0

類也,把你的更新接口 –

+0

@Roy請檢查我已經更新我的版本的類和接口 – Swapnil

回答

0

嘗試增加標量轉換器到你的改造實例是這樣的:

.addConverterFactory(ScalarsConverterFactory.create()) 
相關問題