com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated obj

倾然丶 夕夏残阳落幕 提交于 2020-01-26 15:39:26

这个错误是由于操作的json字符串,使用string类型有误。

我要把object对象recomdList解析出来,应该是一个list<T>,代码里需要把recomdList转成string,我直接转报错,应该是转成json才对。JSONObject.toJSONString(recomdList)

一个object对象recomdList转成List<T>代码:

if (recomdList instanceof String){

}else if (recomdList instanceof ArrayList<?>) {
    Gson gson = new Gson();
    JsonArray arry = new JsonParser().parse(JSONObject.toJSONString(recomdList)).getAsJsonArray();
    for (JsonElement jsonElement : arry) {
        recomd_list.add(gson.fromJson(jsonElement,ProductsRecommendListBean.class));
    }
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!