【问题标题】:java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2java.lang.IllegalStateException:应为 BEGIN_ARRAY,但在第 1 行第 2 列是 BEGIN_OBJECT
【发布时间】:2014-07-12 16:39:55
【问题描述】:

我正在使用Retro Fit 在线连接 API。但是我在尝试解析返回的数据时遇到了这个错误。

retrofit.RetrofitError: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2

返回的数据为This格式,数据模型如下:

iGPlaceApi.getStreams(ITEMS_PER_PAGE, pageNumber * ITEMS_PER_PAGE, new Callback<List<mGooglePlacesApiResponse>>() {

            @Override
            public void success(List<mGooglePlacesApiResponse> mGp, Response response) {
                int n = mGp.size();
                Object asa = mGp.toArray();
            }

            @Override
            public void failure(RetrofitError retrofitError) {
                String error = retrofitError.toString();
            }
        });

public class mGooglePlacesApiResponse {

    public String html_attributions;
    //public List<String> html_attributions;
    public String next_page_token;
    public List<place> results;
}

public class place {

    public Geometry geometry;
    public String icon;
    public String id;
    public String name;
    public OpeningHours opening_hours;
    public List<Photo> photo
    ...

【问题讨论】:

  • 你的json是以jsonarray开头的?

标签: java android gson retrofit


【解决方案1】:

List&lt;mGooglePlacesApiResponse&gt; mGp 更改为mGooglePlacesApiResponse mGp。您的 JSON 包含对象而不是列表。

@编辑

顺便说一句,html_attributions 是一个数组

@edit2

好吧,我看到你更正了你的 html_attrubutions

【讨论】:

  • 拯救了这一天。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-28
  • 2021-08-02
  • 2016-07-12
  • 1970-01-01
  • 2022-11-25
  • 2015-03-17
相关资源
最近更新 更多