android - 如何将对象响应数组转换为 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"
}
]
}
]
解决方案
您通过JsonPOJO创建 api 响应的模型类,并在回调中调用 ModelClass 列表
new Callback<List<ModelClass>>()
推荐阅读
- pug - 为哈巴狗转换管道?
- multithreading - 从 openmp 循环调用顺序 intel mkl
- excel - Excel不正确的小数计算百分之一
- android - kotlin.coroutines.intrinsics.CoroutineSingletons 不能转换为 retrofit2.Response
- java - 从返回域对象列表的 RESTful Web 服务端点的响应中动态过滤字段
- ios - 不幸的是删除 Xcode 模拟器
- python - 除了 tkinter 我还能用什么在 python 中创建一个窗口
- html - HTML
- java - Java Swing - GameLoop - 奇怪的结果
- amazon-web-services - 将 JSON 转换为 Parquet 并将对象分类到文件夹中