Add JSONArray to JSONObject

suggest change
// Create a new instance of a JSONArray
JSONArray array = new JSONArray();

// With put() you can add a value to the array.

// Create a new instance of a JSONObject
JSONObject obj = new JSONObject();

try {
    // Add the JSONArray to the JSONObject
    obj.put("the_array", array);
} catch (JSONException e) {

String json = obj.toString();

The resulting JSON string looks like this:


Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents