在我的應用程式中,我試圖從共享首選項中檢索資料并將該值傳遞給提供者。但是,我得到了一個例外
。FormatException (FormatException: 意外的字符(在字符2)。
{token: eyJh...
獲取并傳遞值給提供者的函式如下
Future<void> insertUsertolocal() async {
final storage = new LocalStorage()。
final _user = await storage.getValue(Constants.USER); //從key檢索資料
User user = User.fromJson(jsonDecode(_user)); //收到FortmatException。
print(user.email)。
}
json資料作為字串存盤在共享偏好中
_localStorage.setValue(Constants.USER, user.toString())。
我怎樣才能解決這個問題?
uj5u.com熱心網友回復:
你應該使用jsonEncode()在 _localStorage.setValue。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/309235.html
標籤:
