I am trying to query the marvel API. I believe my decodable is wrong. I have the following code:
struct ReturnedData : Decodable {
var id : Int?
var name : String?
var description : String?
}
var savedData : [ReturnedData] = []
let urlString = "https://gateway.marvel.com/v1/public/characters?ts=1&apikey=\(myAPIKey)"
let url = URL(string: urlString)
let session = URLSession.shared
let dataTask = session.dataTask(with: url!) { (data, response, error) in
guard let data = data else {return}
do {
let recievedData = try JSONDecoder().decode([ReturnedData].self, from: data)
self.savedData = recievedData
} catch {
print(error)
}
}
dataTask.resume()
}
I am getting the following error message: typeMismatch(Swift.Array, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Array but found a dictionary instead.", underlyingError: nil))
according to the documentation, I should get all of the below: Character
id (int, optional): The unique ID of the character resource., name (string, optional): The name of the character. description (string, optional): A short bio or description of the character. modified (Date, optional): The date the resource was most recently modified. resourceURI (string, optional): The canonical URL identifier for this resource. urls (Array[Url], optional): A set of public web site URLs for the resource. thumbnail (Image, optional): The representative image for this character. comics (ComicList, optional): A resource list containing comics which feature this character. stories (StoryList, optional): A resource list of stories in which this character appears events (EventList, optional): A resource list of events in which this character appears. series (SeriesList, optional): A resource list of series in which this character appears.
Also, any tips on how to get the thumbnail image is appreciated.