+ Start a Discussion
Priyesh Misquith 12Priyesh Misquith 12 

Gettinng Null value agfter deserialize the json - integration

I am getting null as value after desearlise of the callout response
 
List<Map<String, Object>> myMaps = new List<Map<String, Object>>();
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://priyesh01.github.io/SampleJson/JsonDummy.json');
request.setMethod('GET');
HttpResponse response = http.send(request);
System.debug('$$Response'+response.getBody());
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
   System.debug('I am able to hit end point');
   Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
       		myMaps = new List<Map<String, Object>>();
      List<Object> draftAlarmsRequest = (List<Object>) results.get('draftAlarmsRequest');
  system.debug('$$ draftAlarmsRequest '+draftAlarmsRequest);
}
I am geeting null in the draftAlarmsRequest.

 
Best Answer chosen by Priyesh Misquith 12
Danish HodaDanish Hoda
hi Priyesh,
In any response, first check the type and structure of data you are getting.
You can refer below working code to get insights:
List<Map<String, Object>> myMaps = new List<Map<String, Object>>();
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://priyesh01.github.io/SampleJson/JsonDummy.json');
request.setMethod('GET');
HttpResponse response = http.send(request);
System.debug('$$Response'+response.getBody());
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
   System.debug('I am able to hit end point');
   Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
    myMaps = new List<Map<String, Object>>();
    system.debug('-->> '+results.get('Body'));
	Map<String, Object> res1 = (Map<String, Object>) JSON.deserializeUntyped(JSON.serialize(results.get('Body')));
	system.debug('-->> ' +res1.get('getDraftAlarmsRequestByAlarmsRequestIdResponse'));
	Map<String, Object> res2 = (Map<String, Object>) JSON.deserializeUntyped(JSON.serialize(res1.get('getDraftAlarmsRequestByAlarmsRequestIdResponse')));
	system.debug('-->> ' +res2.get('return'));
    //List<Object> draftAlarmsRequest = (List<Object>) results.get('draftAlarmsRequest');
	Map<String, Object> draftAlarmsRequest = (Map<String, Object>) JSON.deserializeUntyped(JSON.serialize(res2.get('return')));
	system.debug('$$ draftAlarmsRequest '+draftAlarmsRequest);
	Map<String, Object> res3 = (Map<String, Object>) JSON.deserializeUntyped(JSON.serialize(draftAlarmsRequest.get('draftAlarmsRequest')));
	system.debug('-->> res3 '+res3);
}