【发布时间】:2021-01-29 18:52:44
【问题描述】:
在这里,我根据下面给出的指南提供了代码工作示例,并且似乎得到了空值。
这是我完整的 JSON 数据,
some: {
"success": true,
"data":
[
{
"15-10-2020": [
{
"id": 100,
"details": {
"_id": 1,
"_title": "My Title"
},
"created_at": "2020-10-15"
},
{
"snf_id": 101,
"details": {
"_id": 1,
"_title": "My Title"
},
"created_at": "2020-10-15"
},
{
"snf_id": 102,
"details": {
"_id": 1,
"_title": "My Title"
},
"created_at": "2020-10-15"
}
],
"30-09-2020": [
{
"snf_id": 301,
"details": {
"_id": 8,
"_title": "My Title"
},
"created_at": "2020-09-30"
}
]
}
],
"message": "Successfully Retrieved"
}
struct Response : Codable {
var success : Bool?
var data : [Data]?
var message : String?
}
struct Data: Codable {
var snf_id: Int?
var details: Details?
var created_at: String?
}
// MARK: - Details
struct Details: Codable {
var _id: Int?
var _title: String?
}
let Response = try JSONDecoder().decode(Response.self, from: data)
为数据返回空值,
▿ 回应 ▿ 成功:可选 - 一些:真的 ▿ 数据:可选 ▿ 一些:1 个元素 ▿ 0 : 数据 - snf_id:无 - 细节:无 - created_at:无 ▿ 留言:可选 - 一些:“成功检索”
【问题讨论】: