2

I want to send my request parameters in JSON format. My problem is I am not able send request like below format. Can anybody help me to resolve it?

{
    "user": {
        "email" : "",
        "password": "",
        "password_confirmation": ""
    }
}
3
  • Create the JsonObject and set the values which you want Commented Jul 26, 2017 at 11:55
  • can you tried this Solution Commented Jul 26, 2017 at 11:55
  • You only include example of JSON db. Please include your code that you used for sending the request as you mentioned above. Commented Jul 26, 2017 at 12:02

2 Answers 2

3

Try this

      try {
            JSONObject parent = new JSONObject();
            JSONObject jsonObject = new JSONObject();

            jsonObject.put("email", "email");
            jsonObject.put("password", "password");
            jsonObject.put("password_confirmation", "password_confirmation");
            parent.put("user", jsonObject);
            Log.d("output", parent.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }

It will return this JsonObject output

{
    "user": {
        "email" : "email",
        "password": "password",
        "password_confirmation": "password_confirmation"
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Its very useful. Thank you very much.
If it works for you, please accept the answer @user3606971
Can you help me send JSON request as below : { "gigs_list_ids" : { "2640" : 38 }, "gigs_add_ons_list_ids" : { "2641" : 65, "2642" : 66 } }
0

you are probably looking for something like this

try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("email", "value");
            jsonObject.put("password", "value");
            jsonObject.put("password_confirmation", "value");

            JSONObject parent = new JSONObject();
            parent.put("user", jsonObject);
        }catch (JSONException e) {
            e.printStackTrace();
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.