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

How to include a screen flow in a Lightning Web Component

 Hi, Assume  you have a flow called "Quick Contact Creation" and API Name for the same is "Quick_Contact_Creation". To i...