I have JSON structure as:
"periods": {
"2018-06-07": [
{
"firstName": "Test1",
"lastName": "Test1"
}
],
"2018-06-06": [
{
"firstName": "Test1",
"lastName": "Test1"
}
]
}
I tried to parse it like this:
public struct Schedule: Codable {
public let periods: Periods
}
public struct Periods: Codable {
public let unknown: [Inner]
public struct Inner: Codable {
public let firstName: String
public let lastName: String
}
private struct CustomCodingKeys: CodingKey {
var stringValue: String
init?(stringValue: String) {
self.stringValue = stringValue
}
var intValue: Int?
init?(intValue: Int) {
return nil
}
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CustomCodingKeys.self)
self.unknown = try container.decode([Inner].self, forKey: CustomCodingKeys(stringValue: "2018-06-06")
}
}
But I can get result for only one value (2018-06-06)
. I have multiple dates here that I want to parse. Is this possible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…