Create nested JSON object
suggest changeTo 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents