在flutter中的共享首选项中将数据存储为对象 [英] Store data as an object in shared preferences in flutter
本文介绍了在flutter中的共享首选项中将数据存储为对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以共享的首选项存储对象,该对象中包含一些字段,例如名称,年龄,电话号码等.我不知道如何在共享的首选项中以波动的方式存储对象.
I want to store an object in shared preferences which contains some fields in it like name, age, phone number etc. I don't know how to store an object in shared preferences in flutter.
推荐答案
在保存之前需要将其序列化为JSON,在阅读后需要反序列化
You need to serialize it to JSON before saving and deserialize after reading
请参见 https://flutter.io/docs/development/data-and -backend/json 了解详情
这篇关于在flutter中的共享首选项中将数据存储为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文