I am new to that in the use of JsonArrayRequest
or JsonObjectRequest
, using the library Android Volley .
I'm doing an Android login when I try to send the data through a post that does not get it from the web service, but I do not send it.
public void validateUser(){
//Obtenemos el usuario y contraseña de login
final String userName = usuario.getText().toString().trim();
final String passwordField = password.getText().toString().trim();
queue = requestSingleton.getInstance(this.getApplicationContext()).getRequestQueue();
//hacemos el login
progressBar.setMessage("Iniciado sesión");
progressBar.show();
final JsonArrayRequest jsonObjectRequest = new JsonArrayRequest
(Request.Method.POST,url,null, new Response.Listener<JSONArray>(){
@Override
public void onResponse(JSONArray response) {
try {
progressBar.dismiss();
JSONObject objeto = response.getJSONObject(0);
Toast.makeText(MainActivity.this, "Respuesta del server:"+objeto.getString("usuario"), Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
},new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
progressBar.dismiss();
Toast.makeText(MainActivity.this, "Error en la conexión"+error.getMessage(),Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<>();
//enviamos parametros a la peticion
params.put(KEY_USER, userName);
params.put(KEY_PASSWORD, passwordField);
//retornamos los parametros
return params;
}
};
//agregamos la peticion
queue.add(jsonObjectRequest);
}
The detail is using JsonArrayRequest
or JsonObjectRequest
, because when I use StringRequest