Retrofit2无法访问POJO中的数组

时间:2017-03-14 21:45:50

标签: java android json retrofit2

我想从JSON数组传递数据以在RecyclerView中显示它,但在logcat中有“Items = 0”。任何解决方案?

  

D / RestauransActivity:response = {“controller”:“RestaurantController”,“info”:“找到的餐馆!”,“餐馆”:[],“状态”:true}

     

D / RestauransActivity:Items = 0

    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
}
$.get("content.php", function( data ) {
  $("div").html(data);
  if (data.indexOf("hello") > -1) {
    alert("Hello, world");
  }
});

1 个答案:

答案 0 :(得分:0)

现在一切正常。问题是RestApi类中的错误字段名称。