Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My API returns this JSON:
- {
- "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",
- "department": "5"
- }
- ]
- }
- This is my android function that reads the JSON object:
- private void readUsers() {
- userList.clear();
- managerAdminApi.user(new Callback<ArrayList<ObjectUser>>() {
- @Override
- public void onResponse(@NonNull Call<ArrayList<ObjectUser>> call, @NonNull Response<ArrayList<ObjectUser>> response) {
- ArrayList<ObjectUser> JsonList = response.body();
- for (int i = 0; i < requireNonNull(JsonList).size(); i++) {
- userList.add(new ObjectUser(
- JsonList.get(i).getId(),
- JsonList.get(i).getUsername(),
- JsonList.get(i).getPassword(),
- JsonList.get(i).getCreated(),
- JsonList.get(i).getModified(),
- JsonList.get(i).getGrade(),
- JsonList.get(i).getDepartment()
- ));
- }
- uAdapter.notifyDataSetChanged();
- }
- @Override
- public void onFailure(@NonNull Call<ArrayList<ObjectUser>> call, @NonNull Throwable t) {
- }
- });
- }
- 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