我需要發送類似發送的JSONObject:如何與Android凌空
{
"username": "username",
"password": "password",
"email": "[email protected]",
"usuario": {
"municipio": 1,
"estado": 1
}
}
我怎麼能這樣做?如果我嘗試使用此代碼它不工作:
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;
}
我想我應該創建一個jsonobject
,但我不知道該怎麼做。
我不知道如何創建我的json對象以便在getParams()方法中提交它 –