Еще один простой способ сохранить JsonArray в общих настройках:
public void SaveFriendList(String key, JSONArray value) {
FriendLst = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = FriendLst.edit();
editor.putString(key, value.toString());
editor.commit();
}
public String LoadFriendList() {
MyApplication.FriendLst = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String FriendLsts = MyApplication.FriendLst.getString("Friends", "");
return FriendLsts;
}
Просто позвоните по этому коду, чтобы получить Json: -)
try {
JSONArray jarry1 = new JSONArray(LoadFriendList());
JSONObject jobject;
datamodelfriends.clear();
for (int i = 0; i < jarry1.length(); i++) {
jobject = jarry1.getJSONObject(i);
String FirstName = jobject.get("FirstName").toString();//You can get your own objects like this
datamodelfriends.add(new DataModelFriends(FirstName,...));
}
mAdapter = new CustomeAdapterFriendList(datamodelfriends, MainActivity.this);
RecyclerView_Friends.setAdapter(mAdapter);
} catch (Exception e) {
}