Monday 26 April 2021

JSON parsing using Map sample

 Hi,

Here we are going to learn how to do parsing JSON with the help of Map.

Let's take a simple JSON String


String jsonString = '{"accountRecords": [{"actNumber": "ACT0001","rating":"hot"}]}';

Here let's try to get actNumber and rating attributes values.

Map<String,object>  jsonMap= (Map<String,Object>)JSON.deserializeUntyped(jsonString);

System.debug('jsonMap:'+jsonMap);

List<Object> accountRecordsList= (List<Object>)jsonMap.get('accountRecords');

System.debug('---'+accountRecordsList[0]);
Map<String,Object> accountRecordMap= (Map<String,Object>)accountRecordsList[0];


System.debug('---'+accountRecordMap.get('actNumber'));

System.debug('---'+accountRecordMap.get('rating'));


Reference:

https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_JsonParser.htm

No comments:

Post a Comment

Best Practices for Building Prompt Templates

 Hi, The following best practices should be considered when building prompt templates: Make sure that your prompt templates are concise and ...