在我的应用程序中,我尝试从共享首选项中检索数据,并将该值传递给提供程序。我怎么会遇到异常呢?
FormatException (FormatException: Unexpected character (at character 2)
{token: eyJh...
^ 获取值并将其传递给提供程序的函数如下
Future<void> insertUsertolocal() async {
final storage = new LocalStorage();
final _user = await storage.getValue(Constants.USER); // retrieves data from key
User user = User.fromJson(jsonDecode(_user)); // receives FortmatException
print(user.email);
}json数据以字符串的形式存储在共享首选项中
_localStorage.setValue(Constants.USER, user.toString());如何解决此问题??
发布于 2021-09-16 10:19:17
您应该在_localStorage.setValue中使用jsonEncode()。
https://stackoverflow.com/questions/69206516
复制相似问题