0
JSON配列からデータを渡してRecyclerViewに表示したいが、logcatに "Items = 0"がある。どんな解決策ですか?Retrofit2がPOJOの配列にアクセスできない
D/RestauransActivity:応答= { "コントローラ": "RestaurantController"、 "情報": "レストランが見つかりました。"、 "レストラン":[]、 "ステータス":真}
D/RestauransActivity:アイテム= 0
call.enqueue(new Callback<RestaurantsListResponse>() {
@Override
public void onResponse(Call<RestaurantsListResponse> call, Response<RestaurantsListResponse> response)
{
if(response.isSuccessful())
{
data = new ArrayList<>();
RestaurantsListResponse restaurants = response.body();
Log.d("RestauransActivity", "response = " + new Gson().toJson(restaurants));
data = restaurants.getRestaurants();
Log.d("RestauransActivity", "Items = " + data.size());
RecyclerView recyclerView = (RecyclerView)findViewById(R.id.my_recycler_view);
adapter = new MyRecyclerViewAdapter(data);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(adapter);
}
public class RestaurantsListResponse
{
//...
@SerializedName("restaurants")
@Expose
private List<Restaurant> restaurants = null;
/...
public List<Restaurant> getRestaurants()
{
return restaurants;
}
public void setRestaurants(List<Restaurant> restaurants)
{
this.restaurants = restaurants;
}
}
public class Restaurant
{
//... fields, some setters and getters
}
JSONがPOJOに変換しようとする前に、JSONの外観がどうなっていますか?正しくデシリアライズされていない可能性があります。 –
http://puu.sh/uJ0XT/7ac9de14ba.png –
質問に投稿した回答には、レストランが空いています。これは実際のjsonか受信ですか? – Fred