Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path

错误翻译:期望返回一个对象但是却返回了一个数组

.用 TypeToken 转一下:

        //设置参数
        Gson gson = new Gson();
        List<TotalDataEntry> totalDataList = new ArrayList<>();
        String pic_history = sp.getString("home_hourOffLine", "");
        if (!TextUtils.isEmpty(pic_history)) {
    
    
            //存入json串 将json字符串转换成List集合
            Type listType = new TypeToken<List<TotalDataEntry>>() {
    
    }.getType();
            totalDataList = gson.fromJson(pic_history, listType);
        }

猜你喜欢

转载自blog.csdn.net/ShiXinXin_Harbour/article/details/113663110