Reputation: 21
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": ""
}
}
Upvotes: 2
Views: 1052
Reputation: 18775
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"
}
}
Upvotes: 3
Reputation: 1616
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();
}
Upvotes: 0