tlmarker1968

Untitled

Jun 9th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. I have this JSON response that returns from my API:
  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. "gradename": "Administrator",
  15. "department": "5",
  16. "departmentname": "Operations"
  17. },
  18. {
  19. "id": "2",
  20. "username": "julie",
  21. "password": "testing",
  22. "created": "0000-00-00 00:00:00",
  23. "modified": "0000-00-00 00:00:00",
  24. "grade": "1",
  25. "gradename": "User",
  26. "department": "1",
  27. "departmentname": "Front Desk"
  28. }
  29. ]
  30. }
  31.  
  32. I am using retrofit to load the JSON response. I am using this function to read the JSON into my app:
  33.  
  34. private void readUsers() {
  35. userList.clear();
  36. managerAdminApi.user(new Callback<ObjectUserResponse>() {
  37. @Override
  38. public void onResponse(@NonNull Call<ObjectUserResponse> call, @NonNull Response<ObjectUserResponse> response) {
  39. ObjectUserResponse JsonList = response.body();
  40. assert JsonList != null;
  41. ObjectUser[] data = JsonList.getData();
  42. for (int i = 0, dataLength = data.length; i < dataLength; i++) {
  43. ObjectUser datum = data[i];
  44. userList.add(new ObjectUser(
  45. datum.getId(),
  46. datum.getUsername(),
  47. datum.getPassword(),
  48. datum.getCreated(),
  49. datum.getModified(),
  50. datum.getGrade(),
  51. datum.getGradeName(),
  52. datum.getDepartment(),
  53. datum.getDepartmentname()
  54. ));
  55. }
  56. uAdapter.notifyDataSetChanged();
  57. }
  58.  
  59. @Override
  60. public void onFailure(@NonNull Call<ObjectUserResponse> call, @NonNull Throwable t) {
  61. }
  62. });
  63. }
  64.  
  65. Everything works, except I can not read the array in the response named data. All I can read is the first element, but I need to read the entire array. I thought the code I had would do what I needed, but it only displays the first element.
Add Comment
Please, Sign In to add comment