function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aryan JhaAryan Jha 

Method does not exist or incorrect signature: void get(String) from the type List<Object> at line 14 column 36

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);
if(response.getStatusCode()==200)
{
Map<String,Object>jsonbody=(Map<String,Object>)JSON.deserializeUntyped(response.getBody());
List<Object>result=(List<Object>)jsonbody.get('animal');
String returnvalue=(String) result.get('id');
return retunvalue;
}
}
}
AnudeepAnudeep (Salesforce Developers) 
Hi Aryan, 

I recommend using the following

jsonOutput results = (jsonOutput) JSON.deserialize(response.getBody(), jsonOutput.class);

system.debug('results= ' + results.animal.name);
system.debug('results= ' + results.animal.id);
 
public class AnimalLocator {
	public class cls_animal {
		public Integer id;	
		public String name;	
		public String eats;	
		public String says;	
	}    
public class JSONOutput{
	public cls_animal animal;

   	//public JSONOutput parse(String json){
	//return (JSONOutput) System.JSON.deserialize(json, JSONOutput.class);
	//}
}
    
    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.setHeader('id', String.valueof(id)); -- cannot be used in this challenge :)
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        system.debug('response: ' + response.getBody());
        //Map<String,Object> map_results = (Map<String,Object>) JSON.deserializeUntyped(response.getBody());
        jsonOutput results = (jsonOutput) JSON.deserialize(response.getBody(), jsonOutput.class);
        //Object results = (Object) map_results.get('animal');
		system.debug('results= ' + results.animal.name);
        return(results.animal.name);
    }

}

If you find this information helpful, please mark this answer as Best. It may help others in the community

Thanks, 
Anudeep