You need to sign in to do that
Don't have an account?
Aryan 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;
}
}
}
{
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;
}
}
}
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);
If you find this information helpful, please mark this answer as Best. It may help others in the community
Thanks,
Anudeep