• tiantian guo 18
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi. I have the following JSON being returned from a webservice callout and I want to loop over it and put it into a List<Object> via Apex and return that list to my lightning component.

Here is the JSON:

[{"SUMMARY":"testing1","CUSTOMERUSEREMAIL":"xyz@abc.com","CLOSUREDATE":"2011-11-29T11:35:09.000","OWNERNAME":"Jane Doe","CATEGORYNAME":"Finance and Billing","TICKETID":12345,"STATUSDESCRIPTION":"Closed","CREATIONDATE":"2011-01-17T10:16:00.000","CUSTOMERNAME":"CustomerTest123","STATUSNAME":"Closed","SLANAME":"Billing Query","CUSTOMERUSERNAME":"Customer 1","RESOLUTIONDATE":"2011-11-29T11:35:09.000"},
{"SUMMARY":"testing2","CUSTOMERUSEREMAIL":"abc@xyz.com","CLOSUREDATE":"2011-08-03T13:31:48.000","OWNERNAME":"John Smith","CATEGORYNAME":"Operational Request","TICKETID":98765,"STATUSDESCRIPTION":"Closed","CREATIONDATE":"2011-08-02T09:08:00.000","CUSTOMERNAME":"CustomerTest456","STATUSNAME":"Closed","SLANAME":"Terminations","CUSTOMERUSERNAME":"Customer 2","RESOLUTIONDATE":"2011-08-03T09:28:38.000"},
{"SUMMARY":"testing3","CUSTOMERUSEREMAIL":"testemail@test.com","CLOSUREDATE":"2011-09-06T13:19:17.000","OWNERNAME":"Customer 3","CATEGORYNAME":"Operational Request","TICKETID":01287,"STATUSDESCRIPTION":"Closed","CREATIONDATE":"2011-09-06T09:30:00.000","CUSTOMERNAME":"CustomerTest789","STATUSNAME":"Closed","SLANAME":"Activation 1-49","CUSTOMERUSERNAME":"Customer 3","RESOLUTIONDATE":"2011-09-06T13:19:17.000"}]

I have been trying to get this JSON rendered into a list via Apex with which I can display in a lightning component table. Searched all over online and tried various things but all had their own problems. I don't have a real custom SOBJECT for this I just want to use an Apex Object something like List<Object> foo = new List<Object> foo;

I tried things like having their own class... inner class... etc. Then I stumbled upon JSON2Apex (http://json2apex.herokuapp.com/). This generates a nice class and test class. However my problem is I need a list generated and this seems to only create 1 result. Has anyone had success with this? 

I try this where JSON2ApexTickets is my generated JSON2Apex class:

       JSON2ApexTickets myClass = JSON2ApexTickets.parse(res.getBody());

When I dump out the result like this to see the result:
        system.debug('myClass= ' + myClass);

I see the data coming back only for the first record in my JSON list. How do I get it to an object?