Hello everyone,
I am trying to understand how to decode the JSON response returned by the suggestions/top results endpoint in MusicKit
As you can see the response returns suggestions, which has two different types, Albums and Songs within the same 'suggestions' array. How can I decode the response even if there are different types using a single struct?
{
"results" : {
"suggestions" : [
{
"content" : {
"attributes" : {
"url" : "https:\/\/music.apple.com\/us\/artist\/megan-thee-stallion\/1258989914",
"name" : "Megan Thee Stallion",
"genreNames" : [
"Hip-Hop\/Rap"
]
},
"id" : "1258989914",
"relationships" : {
"albums" : {
"data" : [
{
"href" : "\/v1\/catalog\/us\/albums\/1537889223",
"type" : "albums",
"id" : "1537889223"
}
],
"next" : "\/v1\/catalog\/us\/artists\/1258989914\/albums?offset=25",
"href" : "\/v1\/catalog\/us\/artists\/1258989914\/albums"
}
},
"href" : "\/v1\/catalog\/us\/artists\/1258989914",
"type" : "artists"
},
"kind" : "topResults"
},
{
"content" : {
"href" : "\/v1\/catalog\/us\/artists\/991187319",
"attributes" : {
"genreNames" : [
"Hip-Hop\/Rap"
],
"url" : "https:\/\/music.apple.com\/us\/artist\/moneybagg-yo\/991187319",
"name" : "Moneybagg Yo"
},
"id" : "991187319",
"type" : "artists",
"relationships" : {
"albums" : {
"href" : "\/v1\/catalog\/us\/artists\/991187319\/albums",
"data" : [
{
"id" : "1550876571",
"href" : "\/v1\/catalog\/us\/albums\/1550876571",
"type" : "albums"
}
],
"next" : "\/v1\/catalog\/us\/artists\/991187319\/albums?offset=25"
}
}
},
"kind" : "topResults"
}
]
}
}