I have this json
{
"status": [
{
"state": "checked",
"errorCode": "123",
"userId": "123456"
}
]
}
this is an array of statuses but is implemented badly because can be just one so I would like to decode just the status object
struct StatusResponse: Codable {
let state: String
let error: String
let id: String
enum CodingKeys: String, CodingKey {
case state = "state"
case error = "errorCode"
case id = "userId"
}
}
I try to custom decode it
let container = try decoder.container(keyedBy: ContainerKeys.self)
var statuses = try container.nestedContainer(keyedBy: CodingKeys.self, forKey: .status)
but as expected I get "Expected to decode Dictionary<String, Any> but found an array instead."
how I can have access to the first object from statuses variable and decode it into StatusResponse? or some other idea on how to procede?