I need to send something like:
{
"username": "username",
"password": "password",
"email": "email@email.com",
"usuario": {
"municipio": 1,
"estado": 1
}
}
How can I do that? If I try with this code it doesn't work:
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(getApplicationContext(), R.string.AlertaExito, Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("username", txtusuario.getText().toString());
params.put("password", txtpassword.getText().toString());
params.put("email", txtemail.getText().toString());
params.put("estado", txtestado.getText().toString());
params.put("municipio", txtmunicipio.getText().toString());
return params;
}
I think I should create a jsonobject
but I don't know how to do that.