java.lang.IllegalStateException:预期为 BEGIN_ARRAY,但在第 1 行第 2 列是 BEGIN_OBJECT

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24715075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 14:23:46  来源:igfitidea点击:

java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2

javaandroidgsonretrofit

提问by Maven

I am using Retro Fitto connect to API online. But I am getting this error while trying to parse the returned data.

我正在使用Retro Fit在线连接到 API。但是在尝试解析返回的数据时出现此错误。

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

The data being returned is in Thisformat and model for data is also given below:

返回的数据采用这种格式,数据模型也如下所示:

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
    ...

采纳答案by Than

Change List<mGooglePlacesApiResponse> mGpto mGooglePlacesApiResponse mGp. Your JSON contains object not list.

更改List<mGooglePlacesApiResponse> mGpmGooglePlacesApiResponse mGp。您的 JSON 包含对象而不是列表。

@edit

@编辑

Btw, html_attributions is an array

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

@edit2

@编辑2

Well, i see you corrected your html_attrubutions

嗯,我看到你更正了你的 html_attrubutions