以共享首选项保存json响应

时间:2018-06-04 07:38:41

标签: json shared preference

{
    "uau_id": 26,
    "u_id": 6,
    "au_id": 15,
    "element_id": 6,
    "date_created": "2018-06-01T09:38:39.974585Z",
    "users": 6,
    "device_id": "dtvB8TgxmXM:APA91bFnrIhO0rYiX5XSexRKSW9VBAjLiabQwrt4ccgkTbbNEMn5Ltgl-mX1wdZuVhbcX0nx5co1UEyi1Jw11EXnCrLqbgg82BFKTA-yVYiWLfQdLSOr6dM_NUHIx1NZCGPcm08p6Xs4",
    "audittype": 15,
    "infograph": 204
}

这是json回复

我只需要在共享首选项中保存uau_is及其值

1 个答案:

答案 0 :(得分:0)

如果要存储响应,更好的方法是将内容写入文件。如果你只想存储一些你可以这样做的值

SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
 editor.putString("key_from_json", "String_value_from_json");
 editor.putInt("key_from_json","int_value_from_json");
 editor.commit();