I want to parse this json file and decode and add them into list. However, couldn't find a way to that. I tried this:
struct flightsPost: Codable {
var data: flightDate
}
struct flightDate: Codable {
var origin: String
var destination: String
var price: Int
var airline: String
var flight_number: String
var departure_at: String
var return_at: String
var transfers: String
var expires_at: String
}
Couldn't find a place and how to put dates these structs. Please help I am really struggling.
CodePudding user response:
Your structure is wrong. The data child is not a single object but a collection of type [String:flightDate]
or if you decode it with a custom dateformatter [Date:flightDate]
.
struct flightsPost: Codable {
var data: [String:flightDate]
}