【发布时间】:2021-04-19 14:13:58
【问题描述】:
我尝试使用 json 对象更新 sharePreference 值。 首先,我创建带有名称的 json 对象,然后更新 sharedPreference 中的对象。 但是,我无法获取 json 对象名称。请帮帮我。
team1.put("name", "India")
updateData(team1)
private fun updateData(data: JSONObject) {
val sharedPref: SharedPreferences = getSharedPreferences("SharedPref1", 0)
val editor:SharedPreferences.Editor = sharedPref.edit()
editor.putString("JSONObjectName",data.toString()) // How to get the JSONObject name?
}
我想要这个,data.name == team1。
【问题讨论】: