android-jsonandroid-async-http

How to post JSON


I want to POST JSON in the following format and GET response.

Mentioned JSON:

{
  "success": true,
  "data": {
    "id": "234576"
    "name": "string"
  }
}

Solution

  • Create 2 json objects like:

    JSONObject parent = new JSONObject();
    JSONObject child = new JSONObject();
    

    In the child object, put:

    parent.put("success", true);
    child.put("id", "234567");
    child.put("name", "string");
    parent.put("data", child);
    

    and simply call ur service using this parent object.