List of usage examples for org.json JSONArray put
public JSONArray put(Object value)
From source file:fr.simon.marquis.secretcodes.util.ExportContentProvider.java
private void saveJsonFile(ArrayList<SecretCode> secretCodes) { try {/* www . j av a 2 s. c o m*/ JSONObject jsonObject = new JSONObject(); jsonObject.put(DEVICE_MANUFACTURER, Build.MANUFACTURER); jsonObject.put(DEVICE_MODEL, Build.MODEL); jsonObject.put(DEVICE_CODE_NAME, Build.DEVICE); jsonObject.put(DEVICE_LOCALE, Locale.getDefault().getDisplayName()); jsonObject.put(ANDROID_VERSION, String.valueOf(Build.VERSION.RELEASE)); JSONArray jsonArray = new JSONArray(); for (SecretCode secretCode : secretCodes) { jsonArray.put(secretCode.toJSON()); } jsonObject.put(SECRET_CODES, jsonArray); FileOutputStream openFileOutput = getContext().openFileOutput(JSON_FILE_NAME, Context.MODE_PRIVATE); openFileOutput.write(jsonObject.toString(4).getBytes()); openFileOutput.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } }