我有以下要解码的JSON:
{
"id":5,
"items_received":[
{
"id":1,
"name":"Doug"
},
{
"id":2,
"name":"smith"
}
]
}
我使用以下结构:
struct Delivery: Equatable, Decodable {
let id: Int
let items: [Item]
private enum CodingKeys: String, CodingKey {
case id
case items = "items_received"
}
}
struct Item: Equatable, Decodable {
let id: Int
let name: String
}
并致电:
{ try self.jsonDecoder.decode(Delivery.self, from: value) }
并获得:
失败:keyNotFound(CodingKeys(stringValue:“ items_received”, intValue:无)