我想在我的应用程序本地保存来自url的JSON文件,并且因为JSON文件每分钟都会更新,所以我希望在后端固定的时间间隔后更新我的本地文件,并在url上更新JSON(不影响前端) )
答案 0 :(得分:2)
一种方法是使用共享首选项来存储JSON字符串,并在需要时更新该字符串。
存储数据:
SharedPreferences settings = getApplicationContext().getSharedPreferences("PREF_NAME", MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString("strJSON", "" + strJSONfromServer);
editor.commit();
要检索数据:
SharedPreferences settings = getApplicationContext().getSharedPreferences("PREF_NAME", MODE_PRIVATE);
String strData = settings.getString("strJSON", "");
清除数据:
SharedPreferences settings = getApplicationContext().getSharedPreferences("PREF_NAME",MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.remove("strJSON");
editor.commit();