You can do it by implementing Decodable protocol's required initializer, init(from:):
extension MyStruct {
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
let idString = try values.decode(String.self, forKey: .id)
id = Int(idString)
}
}
And don't forget to decode values of other properties.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…