-
Notifications
You must be signed in to change notification settings - Fork 8
Save Objects
Hendra Permana edited this page May 6, 2017
·
3 revisions
You can save your (Gson) Objects as an Array.
.saveObjects(arrayObject)
Example :
Profile[] mProfiles mProfiles = new Profile[jsonArray.length()];
for(int i = 0; i < mProfiles.length; i++){
mProfiles[i] = new Gson().fromJson(jsonArray.get(i).toString(), Profile.class);
}
gsonSharedPreferences.saveObjects(mProfiles);
.saveObjects(object, jsonArray)
Example, Profile.class
is your object :
jsonArray = new JSONArray(jsonArrayString);
gsonSharedPreferences.saveObjects(new Profile(), jsonArray);
.saveObjects(object, jsonArrayString)
Example Profile.class
is your object :
-
jsonArrayString
:
[{
"user_id": 667,
"user_name": "blog",
"website": "http://blog.hynra.com"
},
{
"user_id": 668,
"user_name": "devnote",
"website": "http://devnote.hynra.com"
}
]
- code :
gsonSharedPreferences.saveObjects(new Profile(), jsonArrayString);