Example usage for org.json JSONArray put

List of usage examples for org.json JSONArray put

Introduction

In this page you can find the example usage for org.json JSONArray put.

Prototype

public JSONArray put(Object value) 

Source Link

Document

Append an object value.

Usage

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();
    }
}