Gson com.google.gson.JsonSyntaxException:Begin Type不正确

时间:2017-11-27 05:43:56

标签: android gson

我正在尝试从我的博客中读取数据。我的JSON以{..开头,但Gson没有将其存储在我的rssObject中。它抛出BEGIN_ARRAY Expected

protected void onPostExecute(String s) {
    mdialog.dismiss();
    Log.d("gson object-----",s+"");

    rssObject = new Gson().fromJson(s,RSSObject.class);
    // here I am using object but gson expect array, my json starts with 
    //  curl-braces "{" but why this error?
    Log.d("gson object-----",rssObject+"");
    FeedAdapter feedAdapter = new 
    FeedAdapter(rssObject,getBaseContext());
    recyclerView.setAdapter(feedAdapter);
    recyclerView.invalidate();
    feedAdapter.notifyDataSetChanged();
}

//我的RSSObject类         公共类RSSObject     {         public String status;         公共饲料;         公共列表项目;

    public RSSObject(String status, Feed feed, List<Item> items) {
        this.status = status;
        this.feed = feed;
        this.items = items;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Feed getFeed() {
        return feed;
    }

    public void setFeed(Feed feed) {
        this.feed = feed;
    }

    public List<Item> getItems() {
        return items;
    }

    public void setItems(List<Item> items) {
        this.items = items;
    }
}

1 个答案:

答案 0 :(得分:0)

这是因为在你的项目数组中,一些外壳是数组,一些对象看4项。对于json对象或json数组

的所有项应该是相同的
  

&#34; enclosure&#34;:{           &#34; thumbnail&#34;:&#34; http://4.bp.blogspot.com/-1OScwyF67RI/UbGu42S52AI/AAAAAAAAAME/OZgbtgNI8dc/s72-c/lonly.jpeg&#34;         }

在其他项目中

  

&#34; enclosure&#34;:[],