My JSON looks like:
{
"status": true,
"data": {
"img_url": "/images/houses/",
"houses": [
{
"id": "1",
"name": "Kapital",
"url": "https://kapital.com/",
"img": "10fbf4bf6fd2928affb180.svg"
}
]
}
}
And I'm using the next structs:
struct ServerStatus: Decodable {
let status: Bool
let data: ServerData
}
struct ServerData: Decodable {
let img_url: String
let houses: [House]
}
struct House: Decodable {
let id: Int
let img: String
let name: String
let url: String
}
But when I'm using:
let houses = try JSONDecoder().decode(ServerStatus.self, from: data)
I get the next error:
3 : CodingKeys(stringValue: "id", intValue: nil)
- debugDescription : "Expected to decode Int but found a string/data instead."
It's my first time using Decodables and I'm googling this problem but was not able to fix it. Can someone help me to find out what's wrong and maybe explain me that?
When I remove data
part from the ServerStatus
everything works. So the problem is in parsing data
part