You need to sign in to do that
Don't have an account?
Jordan Schatz
JSON.deserialize works for a singe item, but not for a list
I am trying to deserialize some JSON into a custom class. If I deserlize just a single object, it works, but when wrapped in a list, it fails.
Here is an example:
The error I get is System.JSONException: Expected attendanceWrapperClass but found } at [line:1, column:369] basically it errors when the first item in the list ends.
What am I doing wrong?
Here is an example:
public class attendanceWrapperClass { @AuraEnabled public Case eachContact{get;set;} @AuraEnabled public Attendance_Breakfast_Lunch_Snack__c eachAttendance{get;set;} @AuraEnabled public List<Attendance_Breakfast_Lunch_Snack__c> previousAttendanceRecordsList{get;set;} } string wrapperListItems = '[{"eachAttendance":{"Attendance_Code__c":"Y - Yes"},"eachContact":{"Client__c":"0036F00002xYORdQAO","Admission_Pathway_Site__c":"Wolverine Center","WHS_Treatment_Unit__c":"WC CMO Respite","WHS_Treatment_Program__c":"Wolverine Center Respite","Id":"5006F0000240Jv2QAE","Client__r":{"Name":"Cedric Russ","FirstName":"Cedric","LastName":"Russ","Id":"0036F00002xYORdQAO"}}}]'; list<attendanceWrapperClass> wrapperList = (List<attendanceWrapperClass>)JSON.deserialize(wrapperListItems,List<attendanceWrapperClass>.class); system.debug(wrapperList);
The error I get is System.JSONException: Expected attendanceWrapperClass but found } at [line:1, column:369] basically it errors when the first item in the list ends.
What am I doing wrong?
Write the below class separately -
Use below code in your existing class - Let me know if it helps you or not.
Thanks,
Parmanand Pathak