Android JSON handling with org.json suggest change

Add JSONArray to JSONObject

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

// With put() you can add a value to the array.
array.put("ASDF");
array.put("QWERTY");

// 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) {
    e.printStackTrace();
}

String json = obj.toString();

The resulting JSON string looks like this:

{  
   "the_array":[  
      "ASDF",
      "QWERTY"
   ]
}

Feedback about page:

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



Table Of Contents