2016-04-28 234 views
0

我試圖讓在GET方法改造2.x的 使用參數的所有數據,但respon預計BEGIN_ARRAY但BEGIN_OBJECT在改造2java.lang.IllegalStateException:預期BEGIN_ARRAY但BEGIN_OBJECT在改造2

這是我的代碼訪問URL服務

public interface BukuResepMasakanAPI { 
public static String baseURL = "http://10.108.233.76/buku_resep_masakan_service/"; 

//membuat Instance Retrofit 
Retrofit client = new Retrofit.Builder() 
     .baseUrl(baseURL) 
     .addConverterFactory(GsonConverterFactory.create()) 
     .build(); 


@POST("jenis_resep") 
public Call<JenisResepModel> getJenisResep(@Body JenisResepModel model); 

@GET("get_resep_by_jenis/{id_jenis_resep}") 
public Call<List<DetailResepModel>> getDetailResep(@Path("id_jenis_resep") String id_jenis_resep); 

}

,這是我的代碼來調用改造

public void loadData(){ 
    BukuResepMasakanAPI apiService = BukuResepMasakanAPI.client.create(BukuResepMasakanAPI.class); 
    DetailResepModel model = new DetailResepModel(); 
    Log.d("lappet",""+idJenisResep); 
    Call<List<DetailResepModel>> call = apiService.getDetailResep(idJenisResep); 

    //proses call 
    call.enqueue(new Callback<List<DetailResepModel>>() { 
     @Override 
     public void onResponse(Call<List<DetailResepModel>> call, Response<List<DetailResepModel>> response) { 
      List<DetailResepModel> resep = response.body(); 
      Log.d("idjenisresep",""+idJenisResep+" size "+resep.size()); 
     } 

     @Override 
     public void onFailure(Call<List<DetailResepModel>> call, Throwable t) { 
      Toast.makeText(getApplicationContext(),"Failed to connect",Toast.LENGTH_SHORT).show(); 
      Log.d("failed", "" + t.toString()); 
     } 
    }); 
} 

我希望你能幫我解決這個問題

+0

[改造的可能的複製 - java.lang.IllegalStateException:預期BEGIN \ _ARRAY但是BEGIN \ _OBJECT](http://stackoverflow.com/questions/34917713/retrofit-java-lang-illegalstateexception-expected-begin-array-but-was-begin-o) – Bharatesh

回答

0

你的錯誤是說它收到一個JSON對象,但你的回調預期列表。

(我認爲這是錯誤指方法)

@GET("get_resep_by_jenis/{id_jenis_resep}") 
public Call<List<DetailResepModel>> 

你應該嘗試改變,要

@GET("get_resep_by_jenis/{id_jenis_resep}") 
public Call<DetailResepModel> 
+0

當我嘗試像你推薦它將返回object = 0的大小,但我有數據要獲取。 –

+0

這聽起來比你收到的錯誤信息要好,但我無法幫助 –

+0

好,謝謝你的回答 –

相關問題