+ Start a Discussion
Vivek NayakVivek Nayak 

How to cast list<object> in to map

Hi Guys,
I need urgent help . I am deserializing callout response into list<object> which looks like below:
(
{
DealerSelected=true,
address={country=AU, postCode=2154, state=NSW, streetAddress=2 Victoria Ave, suburb=CASTLE HILL},
ealerCode=36333, dealerName=Castle Hill Toyota, 
lastUpdated=2019-11-25, latitude=-33.7345000, localityName=NSW, longitude=150.9810610, sapBranchCode=36333
},
)
i want to iterate over it and get attributes for but unable to read 
using dot notation. 

Below is code :



global class DealerSearchController {
 // Callout method
    @AuraEnabled
    public static ResponseWrapper getDealerList(String SearchString){
    //public static List<object>  getDealerList(String SearchString){
    system.debug('SearchString '+SearchString);  
    ResponseWrapper wr=new ResponseWrapper();         
    Http http=new Http();
    HttpRequest req= new HttpRequest();
    req.setMethod('GET');     
    String endpoint ='URL';
     req.setEndpoint(endpoint);    
     
    HttpResponse res=http.send(req);
    system.debug('Response '+res.getBody());
    List<object> DealerList;    
    if (res.getStatusCode()== 200){ 
        
    
    system.debug('body '+json.deserializeUntyped(res.getBody())) ; 
    Map<String,Object>DeserializedResponse=(Map<String,Object>)json.deserializeUntyped(res.getBody()); 
          
    DealerList= (List<object>) DeserializedResponse.get('locations');    
    system.debug('deserializedResponse '+DeserializedResponse);
    system.debug('Locations '+DealerList);
    wr.DealerList=DealerList; 

}

return wr;

    
    }    
   
 // other method  
    @AuraEnabled
public static void addSelectedDealer(List<Object>selectedDealers,String AccountId){
    //Map<String,Object>obj=New Map<String,Object>(selectedDealers);  
    //Map<String,Object>obj=(Map<String,Object>)selectedDealers;
  //iterating over selectedDealers
    for (object s : selectedDealers){      
    system.debug('record '+s); 
    //system.debug('abc '+s.dealerCode);     //throwing variable doent exist        
    }
    
    }

Can someone help how convert into list<object> into map to get object attributes?

Thanks
SUCHARITA MONDALSUCHARITA MONDAL
Hi Vivek,
Check the below link for the same
https://salesforce.stackexchange.com/questions/106567/how-to-convert-listobject-into-liststring

Thanks,
Sucharita