I have the following code:
Gson gson = new Gson();
//write
SharedPreferences.Editor editor = context.getSharedPreferences(ITEM, 0).edit();
editor.putString(KEY, gson.toJson(hashMapObject));
editor.apply();
//read
SharedPreferences prefs = context.getSharedPreferences(ITEM, 0);
String item = prefs.getString(KEY, null);
java.lang.reflect.Type type = new TypeToken<HashMap<Object1, List<Object2>>>() {
}.getType();
HashMap<Object1, List<Object2>> testHashMap2 = gson.fromJson(item, type);
我收到错误消息:
java.lang.IllegalStateException:应为BEGIN_ARRAY,但为STRING 在第1行第3列的路径$。
该如何解决?