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.
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