0

I'm making a callout to an external API via Apex and processing the response as such:

    HTTPResponse res = http.send(request);
    Map<String, Object> Response = (Map<String, Object>)System.JSON.deserializeUntyped(res.getBody());

This compiles fine, but I get the following error at runtime:

Invalid conversion from runtime type List to Map

The response body is in the following format (list size is always 1):

[
    {
        "licenceID": "543C",
        "status": "Current",
        "expiryDate": "17/11/2018",
    }
]

So I understand that it's detecting this as a list rather than a map but I'm not sure what the best way is to process this List. Essentially, I'd like to be able to get the value for licenceID, using something like this:

String licenceID = String.valueOf(Response.get('licenceId'));
  • try List<Object> Response = (List<Object>)System.JSON.deserializeUntyped(res.getBody()); – Raul Sep 27 '17 at 11:44
0

You can get licenseId value with following code.

 List<Object> Response = (List<Object>)System.JSON.deserializeUntyped(res.getBody());
 Map<String,Object> data = (Map<String,Object>)Response[0];
 System.debug(data.get('licenseId'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.