且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-18 17:25:57

更改列表与LT; mGooglePlacesApiResponse> mGp mGooglePlacesApiResponse mGp 。您的JSON包含的对象不是列表。



@edit

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



@ edit2



好的,我看到你改正了你的html_attrubutions


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

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

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

@edit

Btw, html_attributions is an array

@edit2

Well, i see you corrected your html_attrubutions