【问题标题】:How i can store json response in Shared Prefence in Flutter我如何在 Flutter 的 Shared Preference 中存储 json 响应
【发布时间】:2022-01-03 06:57:51
【问题描述】:

我想在共享首选项中存储一个这个 Json 响应,其中包含一个字段密码,我的响应是

{
    "id": 103,
    "address": "ce5f4e2b82a901768456b0dfd58e7dfa99a1bd0e",
    "privateKey": "91c8b3434a7eb8eb6df73cd7dfbfa3d7cce66d5f4f635fb6d329894c69fa0cab",
    "status": "succeed",
    "password": "1245687"
}

【问题讨论】:

    标签: flutter


    【解决方案1】:

    final SharedPreferences prefs = await SharedPreferences.getInstance();

    //保存值

    prefs.setString("json_response", json.encode(value));

    //读取值

    var value = json.decode(prefs.getString(json_response))

    【讨论】:

    • 我应该在值字段中写什么,api响应字段或其他任何东西..
    • 是的,你必须传递你想要存储的 json
    【解决方案2】:

    我已经回答了一个类似的问题,它回答了在颤振中使用 SharedPreferences 处理 json 数据

    在这里参考答案?? https://stackoverflow.com/a/63413787/9236994

    【讨论】:

    • 那么你的答案列表中哪一个是正确的......
    • 分享了我的答案的链接,您可以参考@atifRaza
    猜你喜欢
    • 2021-03-20
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    • 2020-12-01
    • 2021-03-29
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多