0

How can i deserialize a json string into a list of wrapper in apex ? here is my code :

    public class PageLayoutErrorMsg{
      public String errorId{get;Set;}
      public String errorType{get;Set;}
      public String Message{get;Set;}       
    }
    ...
    LIST<PageLayoutErrorMsg> pageErrors = new LIST<PageLayoutErrorMsg>();
    pageErrors = (LIST<PageLayoutErrorMsg>) JSON.deserialize(c.TECH_DisplayedErrorJSON__c,(LIST<PageLayoutErrorMsg>).class);    

I am obtaining the following syntax error : unexpected token list Have anyone came across this problem?

1 Answer 1

2

Try this:

pageErrors = (List<PageLayoutErrorMsg>) JSON.deserializeUntyped(c.TECH_DisplayedErrorJSON__c); 

OR

pageErrors = (List<PageLayoutErrorMsg>) JSON.deserialize(c.TECH_DisplayedErrorJSON__c,List<PageLayoutErrorMsg>.class); 

Assuming that c.TECH_DisplayedErrorJSON__c has correct json.

1
  • For the list type,I should write : LIST<PageLayoutErrorMsg>.class and not (LIST<PageLayoutErrorMsg>).class
    – vanessen
    Aug 20, 2015 at 10:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .