tlmarker1968

Untitled

Jun 1st, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.54 KB | None | 0 0
  1. This is the JSON that my API return:
  2.  
  3. {
  4.     "success": true,
  5.     "message": "User successfully retrieved",
  6.     "data": {
  7.         "id": "1",
  8.         "username": "admin",
  9.         "password": null,
  10.         "created": "2018-04-15 11:53:28",
  11.         "modified": "2018-04-15 11:53:28",
  12.         "grade": "4",
  13.         "gradename": "Administrator",
  14.         "department": "5",
  15.         "departmentname": "Operations"
  16.     }
  17. }
  18.  
  19. The data part is what i need to parse. I beleive that the data part is another json object. How can I access it from Android?
  20.  
  21.  
  22. This is the code I have used in the past:
  23.  
  24.             managerSecurityApi.login (etUsername.getText ().toString (), etPassword.getText ().toString (), new Callback<ArrayList<ObjectUser>>() {
  25.                 @Override
  26.                 public void onResponse (@NonNull Call<ArrayList<ObjectUser>> call, @NonNull Response<ArrayList<ObjectUser>> response) {
  27.                     ArrayList<ObjectUser> JSONList = response.body();
  28.                     for (int i = 0; i < Objects.requireNonNull(JSONList).size(); i++) {
  29.                         objectUser.add(new ObjectUser (
  30.                                 JSONList.get(i).getId(),
  31.                                 JSONList.get(i).getUsername(),
  32.                                 JSONList.get(i).getGrade(),
  33.                                 JSONList.get(i).getGradename(),
  34.                                 JSONList.get(i).getDepartment(),
  35.                                 JSONList.get(i).getDepartmentname()
  36.                         ));
  37.  
  38. But the information I need to access is in the data object in the JSON response. I am not sure how to access it.
Add Comment
Please, Sign In to add comment