我正在使用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
    ...

最佳答案

List<mGooglePlacesApiResponse> mGp更改为mGooglePlacesApiResponse mGp。您的JSON包含对象未列出。

@编辑

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

@ edit2

好吧,我看到您更正了html_attrubutions

关于java - java.lang.IllegalStateException:预期为BEGIN_ARRAY,但在第1行第2列为BEGIN_OBJECT,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41973137/

10-08 23:59