• Brian Newbold 18
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Can you deserializeUntyped with JSON arrays?
I'm finding it difficult to get down into the "client" level so that I can retrieve ID and Status. 
results.get('items') was easy enough at the top level, but attempting results.get('client') fails.

Using this JSON:
{
    "items": [
        {
            "client": {
                "id": "xyz65240-a8e0-4184-8aaa-8b381ea83ce5",
                "status": "enabled"
            }
        },
        {
            "client": {
                "id": "8b265241-3662-4a49-b7dd-97f948ca9bb6",
                "status": "enabled"
            }
        }
    ]
}

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

List<Object> items = (List<Object>) results.get('items');
    System.debug('Received the following items:');
    for (Object item: items) {
        System.debug('Item:');
        System.debug(item);
    }
Can you deserializeUntyped with JSON arrays?
I'm finding it difficult to get down into the "client" level so that I can retrieve ID and Status. 
results.get('items') was easy enough at the top level, but attempting results.get('client') fails.

Using this JSON:
{
    "items": [
        {
            "client": {
                "id": "xyz65240-a8e0-4184-8aaa-8b381ea83ce5",
                "status": "enabled"
            }
        },
        {
            "client": {
                "id": "8b265241-3662-4a49-b7dd-97f948ca9bb6",
                "status": "enabled"
            }
        }
    ]
}

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

List<Object> items = (List<Object>) results.get('items');
    System.debug('Received the following items:');
    for (Object item: items) {
        System.debug('Item:');
        System.debug(item);
    }