2016-04-28 105 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

好,谢谢你的回答 –

相关问题