Create nested JSON object

suggest change

To produce nested JSON object, you need to simply add one JSON object to another:

JSONObject mainObject = new JSONObject();            // Host object
JSONObject requestObject = new JSONObject();         // Included object

try {
    requestObject.put("lastname", lastname);
    requestObject.put("phone", phone);
    requestObject.put("latitude", lat);
    requestObject.put("longitude", lon);
    requestObject.put("theme", theme);
    requestObject.put("text", message);

    mainObject.put("claim", requestObject);
} catch (JSONException e) {
    return "JSON Error";
}

Now mainObject contains a key called claim with the whole requestObject as a value.

Feedback about page:

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



Table Of Contents