[SalesForce] deserialize json string to list of wrapper

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?

Best Answer

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.

Related Topic