I'm trying parse JSON:
{
"meta": {
"page": 1
},
"search-results": [
{
"id": 41528747
}
]
}
I defined the following structure:
public struct PagedCourses: Codable {
public struct Meta: Codable {
public let page: Int
enum CodingKeys: String, CodingKey {
case page = "page"
}
}
public struct Course: Codable {
public let id: Int
enum CodingKeys: String, CodingKey {
case id = "id"
}
}
public let meta: Meta
public let search_results: [Course]
}
When I get data, I get an error.
let courses = try? JSONDecoder().decode(PagedCourses.self, from: data)
I think that the error in the name of the variable 'search_results', but I can not rename it.
How can I parse this data?