You need to sign in to do that
Don't have an account?
EmilienGuichard
Apex rest callout - get return object data
Hi,
I am making an apex rest callout and I am getting a list of objects
Here is an exemple of an object :
Thanks a lot.
I am making an apex rest callout and I am getting a list of objects
if (response.getStatusCode() == 200) { List<Object> results = (List<Object>) JSON.deserializeUntyped(response.getBody()); // Cast the values in the 'equipements' key as a list List<Object> equipements = (List<Object>) results; System.debug('Received the following equipements:'); for (Object equipement : equipements) { System.debug(equipement.get('cost'));and I am getting an error "Method does not exist or incorrect signature: [Object].get(String)" when I try to access an ojbect field.
Here is an exemple of an object :
{_id=55d66226726b611100aaf741, cost=5000, lifespan=120, maintenanceperiod=365, name=Generator 1000 kW, quantity=5, replacement=false, sku=100003}What is the right way to do it ?
Thanks a lot.
First of all your JSON body should have to the following format:
So JSON.deserializeUntyped method can parse it to a Map<String,Object>. Then you can access to any of the elements within the map with the following: Hope this help you.
All Answers
First of all your JSON body should have to the following format:
So JSON.deserializeUntyped method can parse it to a Map<String,Object>. Then you can access to any of the elements within the map with the following: Hope this help you.