2017-11-02 12 views
0

申し訳ありませんが、私は改造を使用して、私のAndroidアプリからそれを消費します。はレトロフィットのAndroidは、私の悪い英語</p> <p>私はJSONで次の形式で提供するWebサービスを持っているため

{"datos": 
[{"codigo_centro":"Plantacion","descripcion_articulo":"Banano", "categoria_centro":"Admin"}, 
{"codigo_centro":"Finca","descripcion_articulo":"Finca ","categoria_centro":"Admin"}, 
{"codigo_centro":"Pante","descripcion_articulo":"Pante","categoria_centro":"Admin"} 
],"error":false} 

この私のapiserviceある

@GET("obtener_centro.php") 
Call<CentroResponse> getDatos(); 

応答

@SerializedName("datos") 
private ArrayList<Centro> datos; 
private boolean Error; 

コールバック

class CentroCallBack implements Callback<CentroResponse> { 
    @Override 
    public void onResponse(Call<CentroResponse> call, Response<CentroResponse> response) { 
     if (response.isSuccessful()) { 
      CentroResponse centroResponse = response.body(); 
      if(!centroResponse.isError()) { 
       if(centroResponse.getDatos()!=null){ 
//      poblarSpinnerCentro(centroResponse.getDatos()); 
       } 
      } 
     }else{ 
      Toast.makeText(reporteActivity.this, "Ha Ocurrido un Error en el Formato de Respuesta", Toast.LENGTH_SHORT).show(); 
     } 
    } 
    @Override 
    public void onFailure(Call<CentroResponse> call, Throwable t) { 
     Toast.makeText(reporteActivity.this, "Fallo la conexion a Internet: "+call.request().url()+" "+t.getMessage(), Toast.LENGTH_SHORT).show(); 
    } 
} 

public void obtenerCentros() { 
    try{ 
     Call<CentroResponse> call = OPCApiAdapter.getApiService().getDatos(); 
     call.enqueue(new CentroCallBack()); 
    }catch(Exception e){ 
     Log.e("Error",e.getMessage()); 
    } 
} 

私は私のArrayListを通過しようとすると、すべてのデータがnull

です

私が間違っていることを知っていますか?

これは私がlogcatで受け取る答え

11-02 18:23:19.339 25501-25849/com.fgtit D/OkHttp: Transfer-Encoding: chunked 
    11-02 18:23:19.339 25501-25849/com.fgtit D/OkHttp: Content-Type: application/json 
    11-02 18:23:19.352 25501-25849/com.fgtit D/OkHttp: {"datos": 
    [{"codigo_centro":"Plantacion","descripcion_articulo":"Banano", "categoria_centro":"Admin"}, 
    {"codigo_centro":"Finca","descripcion_articulo":"Finca ","categoria_centro":"Admin"}, 
    {"codigo_centro":"Pante","descripcion_articulo":"Pante","categoria_centro":"Admin"} 
    ],"error":false} 11-02 18:23:19.353 25501-25849/com.fgtit D/OkHttp: <-- END HTTP (31547-byte body) 
    11-02 18:23:19.518 25501-25501/com.fgtit V/ActivityThread: Finishing stop of ActivityRecord{3430af23 [email protected] {com.fgtit/report.activity.activityMenu}}: show=false [email protected] 

答えて

0

まず第一には、あなたのアプリがあなたのAPIに達した場合、あなたは確認する必要があります。これを行うには、ブレークポイントをif (response.isSuccessful()) {行に、もう1つをToast.makeText行にドロップします。プロジェクトをデバッグすると、APIの応答が表示されます。

その後、応答が成功したかどうかを確認し、成功した場合はresponse.bodyを確認してください。すべてがうまく見えたら、あなたの返答の本文を印刷して、ここに入れてください。

+0

私の質問を編集してログを追加する –

関連する問題