0

I have this JSON data From where i have to fetch the "id"`

{
    "_embedded": {
        "users": [{
            "id": "5d54e31886d2db014eefbf45",
            "email": "vinothk@hibizsolutions.com",
            "name": "Custom Developer",
            "active": true,
            "gender": "NotSpecified",
            "extension": null,
            "external_phone_number": null,
            "created_at": "2019-08-15T04:44:08Z",
            "_links": {
                "self": {
                    "href": "https://api.talkdeskapp.com/users/5d54e31886d2db014eefbf45"
                }
            }
        }]
    },
    "count": 1,
    "total": 1,
}

I have tried this code but stucked in parsing between Maps.

HttpResponse httpRes = httpToken.send(httpReq);
Map<String, Object> jsonResponse = new  Map<String, Object>();
String resultgetuserid = String.valueOf(httpres.getBody());
System.debug('Response' + resultgetuserid);
jsonResponse = (Map<String, Object>)JSON.deserializeUntyped(httpres.getBody());
System.debug('Response : ' + jsonResponse);
Map<String, Object> myMaps = new Map<String, Object>();
List<Object> myMapObjects = (List<Object>) jsonResponse.get('_embedded');
//System.debug('myMaps' + myMaps);
String userId = ''; // to be retrieved
System.debug('User ID: ' + userId);
return userId;  

Thanks in Advance.

1
1
HttpResponse httpRes = httpToken.send(httpReq);
        Map<String, Object> jsonResponse = new  Map<String, Object>();
        jsonResponse = (Map<String, Object>)JSON.deserializeUntyped(httpres.getBody()); //GET JSON
        System.debug('Response : ' + jsonResponse);
        Map<String, Object> myMaps = new Map<String, Object>();
        myMaps = (Map<String, Object>)jsonResponse.get('_embedded');// FILTER EMBEDDED
        System.debug('myMaps: ' + myMaps);
        List<Object> myMapObjects = (List<Object>) myMaps.get('users'); // SINCE USERS IS LIST store it in list
        Map<String, Object> Users = new Map<String, Object>();
        Users = (Map<String,Object>)myMapObjects[0]; //ASSIGN USERS LIST TO A fresh MAP
        System.debug('User map : ' + Users);
        String userId =String.valueOf(Users.get('id'));// THERE U HAVE THE ID
        System.debug('User ID: ' + userId);
        return userId;  

This will do the magic......Thanks.

1
  • its really impressive. Thanks a lot. – Aishwarya Sep 19 '19 at 7:23

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.