You need to sign in to do that
Don't have an account?
HELP JSON Formatting
hello everyone,
I need some help to be able to get the infomrations of this small part of JSON :
"cancellation_policies":{ "alidays":[ { "text_message":"Penale voli emessi o non emessi: 200 euro a persona", "penalty":{ "money":{ "currency":"EUR", "amount":500 } } } ], "agency":[ { "text_message":"Penale voli emessi o non emessi: 200 euro a persona", "penalty":{ "money":{ "currency":"EUR", "amount":875.43 } } } ] }
I say small part since the passed JSON turns out to be much larger, but I am having difficulty with getting the data from this part only.
I created my wrapper class to help me with the deserialization after I wrote this to be able to get the "cancellation_policies" part
public Map<String, Object> serviceInfo; this.serviceInfo = (Map<String, Object>) deserializedObj.get('cancellation_policies'); system.debug('cancellation_policies' +serviceInfo);
Now, however, i cannot get the information that is within my two lists : alidays and agency,
I should save the information to custom fields such as :
CancellationPolicies__c = alidays.text_message;
CancellationPoliciesPublic__c =agencies.text_message;
AlidayPolicieAmount__c alidays.penalty.money.amount;
etc.
Thanks for help.
Here's a sample Apex class that does that: You can then use this class to parse the JSON and populate the custom fields in your Salesforce records:
Make sure to replace YourObject__c with the actual API name of your Salesforce custom object where you want to store this information.
I hope this helps
Julien