【发布时间】:2021-10-21 21:29:35
【问题描述】:
我正在尝试在 sharedPreferences 中保存 Map<String, List<MyObj>>。
我尝试使用经典的sharedPreferences 包,但遇到了麻烦。
如果我将字符串保存到 sharedPreferences,那么当我尝试检索和使用 json.decode(...) 时,
我收到错误 Unhandled Exception: FormatException: Unexpected character (at character 2)...
如果我尝试使用 json.encode(...) 保存它,我会收到错误 Unhandled Exception: Converting object to an encodable object failed: Instance of 'MyObj'。
我要保存的是这样的:
{ExampleString: [Instance of 'MyObj', Instance of 'MyObj'...], ExampleString2: [Instance of 'MyObj', Instance of 'MyObj'...], ...}
我该如何解决这个问题?
有没有可以保存地图的包?
【问题讨论】:
标签: json flutter sharedpreferences flutter-sharedpreference