Android JsonSyntaxException应为BEGIN_对象,但在路径处为BEGIN_数组

Android JsonSyntaxException应为BEGIN_对象,但在路径处为BEGIN_数组,android,json,gson,Android,Json,Gson,我的json是: { "status": "true", "rows": [ { "rec_time": "2017-05-02 11:08:00 " }, { "rec_time": "2017-05-02 10:08:15 " } ], "total": 10000, "code": 200 } 我的RowsBean模型为: public class RowsBean<T> extends BaseBean {

我的json是:

{
"status": "true",
"rows": [
    {
        "rec_time": "2017-05-02 11:08:00 "
    },
    {
        "rec_time": "2017-05-02 10:08:15 "
    }
],
"total": 10000,
"code": 200
}

我的RowsBean模型为:

public class RowsBean<T> extends BaseBean {


    private T rows;
    private int total;


    public T getRows() {
        return rows;
    }

    public void setRows(T rows) {
        this.rows = rows;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

}

public class DataBean {

    private String rec_time;

    public String getRec_time() {
        return rec_time;
    }

    public void setRec_time(String rec_time) {
        this.rec_time = rec_time;
    }
你能告诉我在去序列化时哪里出了问题吗?

使用下面的syndax代替jsonObject.getrows

jsonObject.getAsJsonArrayrows


除了RowsBean的评论之外,我相信您可能还会遇到更多的问题,因为CeRows是一个行类型T的数组。看起来您应该将RowsBean的实现更改为包含一个行类型T[],而不是T。

您的答案是我问题的完美解决方案,谢谢您的帮助,我改进了代码,并在实现类中使用了它。如下所示
public class RowsJsonDeser implements JsonDeserializer<RowsBean<?>> {

    @Override
    public RowsBean<?> deserialize(JsonElement json, Type typeOfT,
                                     JsonDeserializationContext context) throws JsonParseException {

        RowsBean resultBean = new RowsBean();
        if (json.isJsonObject()) {
            JsonObject jsonObject = json.getAsJsonObject();

            Type type = ((ParameterizedType) typeOfT).getActualTypeArguments()[0];
           resultBean.setRows(context.deserialize(jsonObject.get("rows"),type));


        }
        return resultBean;
    }
}
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $