I am completing a challenge for Apex on trailhead. My code is making a callout and receiving certain records in JSON format. I am not able to covert the response into a MAP to process it easily. The response can only be received into a List and further that List cannot be converted to a Map<String, Object>. Please can you see below code and advise what options do I have to traversing the JSON response?
String endpointURL = 'https://th-superbadge-apex.herokuapp.com/equipment?_ga=2.101942977.1923619249.1654550632-503779371.1642224353';
HttpRequest request = new HttpRequest();
Http callOut = new Http();
request.setEndpoint(endpointURL);
request.setMethod('GET');
HttpResponse response = callOut.send(request);
List<Object> listRecords = (List<Object>) JSON.deserializeUntyped(response.getBody());
//Map<String, Object> m = (Map<String, Object>) listRecords;
if (response.getStatusCode() == 200)
{
}
If I uncomment line:
//Map<String, Object> m = (Map<String, Object>) listRecords;
I got following error:
10:02:51.727 Starting Execute Anonymous Apex
Error: Line: 13, Column: 25
Error: Incompatible types since an instance of List<Object> is never an instance of Map<String,Object>
10:02:52.58 ended Execute Anonymous Apex