tlmarker1968

Untitled

Jun 7th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. My API returns this JSON:
  2.  
  3. {
  4. "success": true,
  5. "message": "User list retreived",
  6. "data": [
  7. {
  8. "id": "1",
  9. "username": "admin",
  10. "password": "$2y$10$1h8jP8./G2bvlai3Prgwuu9fHHFsunerV0/aFo.JKKcWPh1MelyHy",
  11. "created": "2018-04-15 11:53:28",
  12. "modified": "2018-04-15 11:53:28",
  13. "grade": "4",
  14. "department": "5"
  15. }
  16. ]
  17. }
  18.  
  19. This is my android function that reads the JSON object:
  20.  
  21. private void readUsers() {
  22. userList.clear();
  23. managerAdminApi.user(new Callback<ArrayList<ObjectUser>>() {
  24. @Override
  25. public void onResponse(@NonNull Call<ArrayList<ObjectUser>> call, @NonNull Response<ArrayList<ObjectUser>> response) {
  26. ArrayList<ObjectUser> JsonList = response.body();
  27. for (int i = 0; i < requireNonNull(JsonList).size(); i++) {
  28. userList.add(new ObjectUser(
  29. JsonList.get(i).getId(),
  30. JsonList.get(i).getUsername(),
  31. JsonList.get(i).getPassword(),
  32. JsonList.get(i).getCreated(),
  33. JsonList.get(i).getModified(),
  34. JsonList.get(i).getGrade(),
  35. JsonList.get(i).getDepartment()
  36. ));
  37. }
  38. uAdapter.notifyDataSetChanged();
  39. }
  40.  
  41. @Override
  42. public void onFailure(@NonNull Call<ArrayList<ObjectUser>> call, @NonNull Throwable t) {
  43. }
  44. });
  45. }
  46.  
  47. I am looking for a way for android to read the data list from the response into an array. But as you can see I have the success and message fields in the response. How can I read just the data array part of the response? Thanks
Add Comment
Please, Sign In to add comment