Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I have this JSON response that returns from my API:
- {
- "success": true,
- "message": "User list retreived",
- "data": [
- {
- "id": "1",
- "username": "admin",
- "password": "$2y$10$1h8jP8./G2bvlai3Prgwuu9fHHFsunerV0/aFo.JKKcWPh1MelyHy",
- "created": "2018-04-15 11:53:28",
- "modified": "2018-04-15 11:53:28",
- "grade": "4",
- "gradename": "Administrator",
- "department": "5",
- "departmentname": "Operations"
- },
- {
- "id": "2",
- "username": "julie",
- "password": "testing",
- "created": "0000-00-00 00:00:00",
- "modified": "0000-00-00 00:00:00",
- "grade": "1",
- "gradename": "User",
- "department": "1",
- "departmentname": "Front Desk"
- }
- ]
- }
- I am using retrofit to load the JSON response. I am using this function to read the JSON into my app:
- private void readUsers() {
- userList.clear();
- managerAdminApi.user(new Callback<ObjectUserResponse>() {
- @Override
- public void onResponse(@NonNull Call<ObjectUserResponse> call, @NonNull Response<ObjectUserResponse> response) {
- ObjectUserResponse JsonList = response.body();
- assert JsonList != null;
- ObjectUser[] data = JsonList.getData();
- for (int i = 0, dataLength = data.length; i < dataLength; i++) {
- ObjectUser datum = data[i];
- userList.add(new ObjectUser(
- datum.getId(),
- datum.getUsername(),
- datum.getPassword(),
- datum.getCreated(),
- datum.getModified(),
- datum.getGrade(),
- datum.getGradeName(),
- datum.getDepartment(),
- datum.getDepartmentname()
- ));
- }
- uAdapter.notifyDataSetChanged();
- }
- @Override
- public void onFailure(@NonNull Call<ObjectUserResponse> call, @NonNull Throwable t) {
- }
- });
- }
- 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