首页 > 解决方案 > 如何将对象响应数组转换为 Ratrofit

问题描述

[
  {
    "appointment_id": 20,
    "doctor_id": "1",
    "user_id": "25",
    "booked_for": "2",
    "gender": null,
    "age": null,
    "patient_phone": null,
    "patient_name": null,
    "rel_with_user": null,
    "patient_address": null,
    "appointment_date": "2019-09-22",
    "time_slot": "11:40 AM",
    "is_emergency": "0",
    "visiting_place_id": "1",
    "complete_date": "2019-09-21 23:10:00",
    "reported_dieses": null,
    "note": "",
    "fees": "150.00",
    "parent_appoinment_id": null,
    "reshedule_date": null,
    "status_id": "1",
    "created_at": "2019-09-04 11:38:52",
    "created_by": "25",
    "updated_at": "2019-09-20 10:21:20",
    "updated_by": "1",
    "medicines": [
      {
        "id": 13,
        "appt_id": "20",
        "medicin_id": "3",
        "dose": "kjouiyuouoiuoiu",
        "frequency": "ewrtwet3434",
        "comment": "etetrwetrasdf",
        "created_by": "12",
        "updated_by": "12",
        "is_active": "1",
        "created_at": "2019-12-25 21:02:30",
        "updated_at": "2019-12-25 21:02:30"
      },
      {
        "id": 14,
        "appt_id": "20",
        "medicin_id": "4",
        "dose": "aoaokjsdkj",
        "frequency": "oioiuyuyu",
        "comment": "lakjslfdjasjsdl",
        "created_by": "12",
        "updated_by": "12",
        "is_active": "1",
        "created_at": "2019-12-25 21:02:30",
        "updated_at": "2019-12-25 21:02:30"
      },
      {
        "id": 15,
        "appt_id": "20",
        "medicin_id": "3",
        "dose": "kjouiyuouoiuoiu",
        "frequency": "ewrtwet3434",
        "comment": "etetrwetrasdf",
        "created_by": "12",
        "updated_by": "12",
        "is_active": "1",
        "created_at": "2019-12-25 21:04:17",
        "updated_at": "2019-12-25 21:04:17"
      },
      {
        "id": 16,
        "appt_id": "20",
        "medicin_id": "4",
        "dose": "aoaokjsdkj",
        "frequency": "oioiuyuyu",
        "comment": "lakjslfdjasjsdl",
        "created_by": "12",
        "updated_by": "12",
        "is_active": "1",
        "created_at": "2019-12-25 21:04:17",
        "updated_at": "2019-12-25 21:04:17"
      },
      {
        "id": 17,
        "appt_id": "20",
        "medicin_id": "3",
        "dose": "kjouiyuouoiuoiu",
        "frequency": "ewrtwet3434",
        "comment": "etetrwetrasdf",
        "created_by": "12",
        "updated_by": "12",
        "is_active": "1",
        "created_at": "2020-01-06 17:59:08",
        "updated_at": "2020-01-06 17:59:08"
      }
    ],
    "labtest": [
      {
        "id": 3,
        "appt_id": "20",
        "test_name": "ABC",
        "comment": "ABC INS",
        "created_by": "12",
        "updated_by": "12",
        "created_at": "2019-12-25 21:02:30",
        "updated_at": "2019-12-25 21:02:30"
      },
      {
        "id": 4,
        "appt_id": "20",
        "test_name": "ABC",
        "comment": "ABC INS",
        "created_by": "12",
        "updated_by": "12",
        "created_at": "2019-12-25 21:02:30",
        "updated_at": "2019-12-25 21:02:30"
      },
      {
        "id": 5,
        "appt_id": "20",
        "test_name": "ABC",
        "comment": "ABC INS",
        "created_by": "12",
        "updated_by": "12",
        "created_at": "2019-12-25 21:04:17",
        "updated_at": "2019-12-25 21:04:17"
      },
      {
        "id": 6,
        "appt_id": "20",
        "test_name": "ABC",
        "comment": "ABC INS",
        "created_by": "12",
        "updated_by": "12",
        "created_at": "2019-12-25 21:04:17",
        "updated_at": "2019-12-25 21:04:17"
      }
    ]
  }
]

标签: android

解决方案


您通过JsonPOJO创建 api 响应的模型类,并在回调中调用 ModelClass 列表

new Callback<List<ModelClass>>()

推荐阅读