You are receiving data, and the "let data = data" command is okay.
So presumably the failure occurs on:
if let decodedResponse = try? JSONDecoder().decode(FDCResponse.self, from: data) {
You don't include a definition of FDCResponse, so I can't test that.
However, you can try what I did:
if let data = data {
if let dataString = String(data: data, encoding: .utf8) {
print("got dataString: \n\(dataString)")
}
// ...
Which prints the incoming json, which looks like this:
{"totalHits":5,"currentPage":1,"totalPages":1,"pageList":[1],"foodSearchCriteria":{"dataType":["Foundation"],"query":"apple fuji","generalSearchInput":"apple fuji","pageNumber":1,"numberOfResultsPerPage":50,
...
So you can compare that json with your FDCResponse, to see where an error might arise.