Skip to main content
While solving the challenge Apex REST Callouts I am getting the mentioned error in the following line of my code :-  Map<String, Object> animal = (Map<String, Object>)results.get('animal');

the complete class is :-

public class AnimalLocator {

    public static String getAnimalNameById(Integer Id) 

    {

        Http http = new Http();

        HttpRequest request = new HttpRequest();

        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/'+Id);

        request.setMethod('GET');

        

        HttpResponse response = http.send(request);

        String animalName;        

        // If the request is successful, parse the JSON response.

        if (response.getStatusCode() == 200) {

            // Deserializes the JSON string into collections of primitive data types.

            Map<String, Object> results = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());

            // Cast the values in the 'animal' key as a map            

            Map<String, Object> animal = (Map<String, Object>)results.get('animal');

            animalName = string.valueOf(animal.get('name'));

            System.debug('Received the following animal:' + animalName);

        }

 

        return animalName;

 

    }

 

}

Can someone please help me?
3 answers
0/9000