【发布时间】:2020-03-27 08:51:35
【问题描述】:
我正在发出一个 HTTP GET 请求,我想保存如下所示的 JSON 响应:
{
"code": 200,
"status": "success",
"patients": [
{
"_id": "5e77c7bbc7cbd30024f3eadb",
"name": "Bogdan Patient",
"username": "bogdanp",
"phone": "0732958473"
},
{
"_id": "5e77c982a2736a0024e895fa",
"name": "Robert Patient",
"username": "robertp",
"phone": "0739284756"
}
]
}
这是我的结构:
struct Doctor: Codable, Identifiable {
let id = UUID()
let patients: [Patients]
}
struct Patients: Codable {
let id: String
let name: String
let phone: String
}
【问题讨论】:
-
您必须在两个结构中添加 CodingKeys 才能跳过
Doctor中的id并映射Patients中的_id。 -
我该怎么做?您可以将其发布在答案中吗?我不熟悉 CodingKeys。
-
那你应该做一些研究,也许从苹果那里读到这个article