Skip to main content

I found this example but I don't understand why it is doing it, from a parson I am getting a List<Object> called results, then I see this

for (Object obj : results) {

Map<String,Object> mapjson = ((Map<String,Object>) obj;

I don't understand this line up there, is it a kind of parsing? I am still new to Salesforce and I have not been able to find an answer.

Thanks

4 answers
  1. Sep 13, 2022, 1:32 PM

    Hi @Flora Lopez

     

    this is type casting into map 

    Map<String,Object> mapjson = ((Map<String,Object>) obj;

     

    for more understanding you need to have a look on below code:-

     

    String input = '[{"01u9000000Ag0bbAAB":"203","01u9000000Ag0bZAAR":"23","Id":"00k0w000003HeFhAAK"}]';

    List<Object> result = (List<Object>)JSON.deserializeUntyped(input);

    for(Object obj : result) {

    Map<String,Object> map1 = (Map<String,Object>)obj;

    for(String key : map1.keyset()) {

    System.debug('Key -->> ' + key);

    System.debug('Value -->> ' + (String)map1.get(key));

    }

    }

0/9000