Is it ok to save a JSON array in SharedPreferences?

The JSON object in Java does not implement serialaizable out of the box. I have seen others extend the class to allow that but for your situation I would simply recommend storing the JSON object as a string and using its toString() function. I have had success with this.

editor.putString("jsondata", jobj.toString());

And to get it back:

String strJson = sharedPref.getString("jsondata","0");//second parameter is necessary ie.,Value to return if this preference does not exist. 

if (strJson != null) {
           try {
               JSONObject response = new JSONObject(strJson);

         } catch (JSONException e) {

         }
  }

http://developer.android.com/reference/org/json/JSONObject.html#JSONObject(java.lang.String)

Leave a Comment