私はこのエラーがあります。これはオブジェクトに関するものです。BEGIN_OBJECTが必要ですが、1行目の2行目のBEGIN_ARRAYでした
これは私のポートです:
http://localhost:3000/cupones
私はこの見ることができます:
[
{
"id": "YLabhnB",
"empresa": "KFC",
"titulo": "Mega Online",
"descripcion": "9 Piezas de pollo, 1 Papa Familiar, 6 Nuggets, 1 Ensalada Familiar, 1 Gaseosa de 1.5Lts",
"precio": 55.9,
"imgUrl": "https://www.kfc.com.pe/Imagenes/800x275/BOTONERA%20MEGA%20ONLINE%202.jpg"
},
{
"id": "LLzwhnA",
"empresa": "Bembos",
"titulo": "Promo Clásica",
"descripcion": "Clásica Mediana + 1 Papa Mediana + 1 Gaseosa 500ml",
"precio": 13.9,
"imgUrl": "http://www.bembos.com.pe/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/o/k/okpromoclasica__2_.png"
}
]
をそれから私はここに、その後私は私のJSONResponseを作成し、jsonschema2pojoを持つクラスを作成しました:
public class JSONResponse {
private Cupon[] cupon;
public Cupon[] getCupon() {
return cupon;
}
}
私はここで私のインターフェイスで何かを変えることができると思います。
私のフラグメントで最後にpublic interface RequestInterface {
@GET("cupones")
Call<JSONResponse> getJSON();
}
:
private void initViews(View rootView){
recyclerView = (RecyclerView) rootView.findViewById(R.id.card_recycler_view);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(new CuponAdapter(new ArrayList<Cupon>()));
loadJSON();
}
private void loadJSON(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://192.168.1.42:3000/")
.addConverterFactory(GsonConverterFactory.create())
.build();
RequestInterface request = retrofit.create(RequestInterface.class);
Call<JSONResponse> call = request.getJSON();
call.enqueue(new Callback<JSONResponse>() {
@Override
public void onResponse(Call<JSONResponse> call, Response<JSONResponse> response) {
JSONResponse jsonResponse = response.body();
data = new ArrayList<>(Arrays.asList(jsonResponse.getCupon()));
adapter = new CuponAdapter(data);
recyclerView.setAdapter(adapter);
}
@Override
public void onFailure(Call<JSONResponse> call, Throwable t) {
Log.d("Error", t.getMessage());
}
});
}
私はそれをどのように解決するだろうか?