Struggling with figuring out how to treat my decodable array where it has different types and structures. Essentially it is an array of data, which leads to an array of 4 types, and each of these types consists of a further array of search results.
Can you use decodable for arrays that have varying formats? Or is it simply to use object dicts?
I will attach my JSON at the bottom
struct SearchData: Decodable {
var success: Bool
var server_response_time: Int
var data: [SearchDataType]
}
//This is the array of 3 of the group types: "Movies", "TV-Shows", "Artists"
struct SearchDataType: Decodable {
let group: String
let data: [SearchDataMovies]
}
// Where group = "Movies"
struct SearchDataMovies: Decodable {
let title: String
let year: String
}
// Where group = "TV-Shows"
struct SearchDataTV: Decodable {
let title: String
let year: Int
}
// Where group = "Artists"
struct SearchDataArtists: Decodable {
let name: String
}