Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. Toast.makeText(getApplicationContext(), "" + URL, Toast.LENGTH_SHORT).show();
  2.  
  3. RequestQueue queue = Volley.newRequestQueue(this);
  4. JsonRequest JsonObjectRequest = new JsonObjectRequest(Request.Method.GET, URL, new Response.Listener<JSONObject>() {
  5.  
  6. @Override
  7. public void onResponse(JSONObject response) {
  8.  
  9. Cliente cliente = new Cliente();
  10. Toast.makeText(getApplicationContext(), "Se ha encontrado el usuario", Toast.LENGTH_SHORT).show();
  11.  
  12. JSONArray jsonArray = response.optJSONArray("datos");
  13. JSONObject jsonObject = null;
  14.  
  15. try {
  16.  
  17. jsonObject = jsonArray.getJSONObject(0);
  18. cliente.setNombre(jsonObject.optString("nombre"));
  19. cliente.setApellido(jsonObject.optString("apellido"));
  20. cliente.setRut(jsonObject.optString("rut"));
  21. cliente.setId(jsonObject.optString("id"));
  22.  
  23. } catch (JSONException e) {
  24.  
  25. e.printStackTrace();
  26.  
  27. }
  28.  
  29.  
  30.  
  31. }
  32. }, new Response.ErrorListener() {
  33. @Override
  34. public void onErrorResponse(VolleyError error) {
  35.  
  36. }
  37. });
  38.  
  39. queue.add(JsonObjectRequest);
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement