gpt4 book ai didi

Android Json 共享首选项

转载 作者:太空狗 更新时间:2023-10-29 16:30:11 24 4
gpt4 key购买 nike

如何在共享首选项中存储包含列表的 JSON 对象Json 对象如:

{
"id": 6,
"name": "1-B",
"section": "B",
"batchCode": "1-2015-2016-B",
"courseId": 1,
"sessionId": 2,
"course": null,
"startDate": "2015-03-31",
"endDate": "2016-03-30"
},
{
"id": 5,
"name": "1-A",
"section": "A",
"batchCode": "1-2015-2016-A",
"courseId": 1,
"sessionId": 2,
"course": null,
"startDate": "2015-03-31",
"endDate": "2016-03-30"
},

如何获取存储在sharedpreferences中的数据

最佳答案

1.转换 jsonObjectString

String yourString = jsonObject.toString();

2.保存

SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
editor.putString("YOURKEY",yourString );
editor.commit();

3.检索

  SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); 
String name = prefs.getString("YOURKEY", null);//If there is no YOURKEY found null will be the default value.
}

关于Android Json 共享首选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41442396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com