I'm trying to understand the best way to parse a json file with the Codable.
This is the json structure.
{
"type": "Feature",
"features": [
{
"type": "Feature",
"geometry": {
"coordinates": [
[10.23, 48.32],
[10.24, 48.33],
[10.25, 48.34],
[10.26, 48.35],
[10.27, 48.36]
]
}
}
]
}
What I need is the list of coordinates. I tried to implement this structures but I have some problems.
struct Root: Codable {
let features: [Features]
}
struct Features: Codable {
let geometry: [Coordinates]
}
struct Geometry: Codable {
let coordinates: [Coordinates]
}
struct Coordinates: Codable {
let latitude: [Double]
let longitude: [Double]
}
Then I call the JSONDecoder function like this
let coordinates = try JSONDecoder().decode(Root.self, from: data)
I think that the error is that the coordinates are in a sublist. I'm new in this world so sorry if the question is a little bit dummy but I haven't find an explanation by my self.