Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path

Error translation: Expected to return an object but returned an array

.Use TypeToken to turn it around:

        //设置参数
        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);
        }

Guess you like

Origin blog.csdn.net/ShiXinXin_Harbour/article/details/113663110