function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jen BranJen Bran 

parse json to apex then access data

I am using the JSON2Apex Heroku app to automatically create my classes (thanks!), but I am having difficulting then using the information that is retrieved from that Class when the data is in an array.

I am doing a call out and then using the app "parse" function to parsing the http response body.  This does allow me to access the data for a particular string from the JSON, but as soon as I hit a LIST I cannot figure out how to access that List data without getting an illegal assignment from List to List.  Since this crosses multiple classes I will just post a snippet below to ask for help.  

        MUser md = New MUser();
        httpResponse http = HttpCallOut.callout('MemberByID',cnt.UniqueID__c,'test',null); //This is just b/c I have a class for calls outs
        UserByID obj = UserByID.parse(http.getBody());
        
        //Parse the info into an object to use in controller
        
        md.Email = obj.Data.Member.MemberEmail;
        md.Country = obj.Data.Member.Country.CountryName;
        md.MStatus = obj.Data.Member.MembershipStatus; //<--These are all individual fields in the JSON (Not array)
        md.StatusHistory = obj.Data.Member.StatusHistory; //Status History is an array of data containing status & createdDate

I understand the Heroku class and how it understands to parse the JSON, but there's very little actual documentation on accessing the information parsed later so I'm finding it difficult to address how the List items are accessed.  Let me know if you need to see the specific JSON2Heroku class, but even just answering in generalities would help!  Thank you thank you thank you!