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
NeeloferNeelofer 

Hi All, Can u plz help me to below question

I am trying to deserialize this response
{"invoiceList":[{"totalPrice":5.5,"statementDate":"2011-10-04T16:58:54.858Z","lineItems":[{"UnitPrice":1.0,"Quantity":5.0,"ProductName":"Pencil"},{"UnitPrice":0.5,"Quantity":1.0,"ProductName":"Eraser"}],"invoiceNumber  ":1},{"totalPrice":11.5,"statementDate":"2011-10-04T16:58:54.858Z","lineItems":[{"UnitPrice":6.0,"Quantity":1.0,"ProductName":"Notebook"},{"UnitPrice":2.5,"Quantity":1.0,"ProductName":"Ruler"},{"UnitPrice":1.5,"Quantity":2.0,"ProductName":"Pen"}],"invoiceNumber  ":2}]}

here I give invoiceNumber with space.

After deserialize this data I got invoiceNumber=null
plz help me this is my code

public class ParsingJsonExample2 {
    public string input                    {set;get;}    
    public string output                {set;get;}
    public void getdata(){
        input='{"invoiceList":[{"totalPrice":5.5,"statementDate":"2011-10-04T16:58:54.858Z","lineItems":[{"UnitPrice":1.0,"Quantity":5.0,"ProductName":"Pencil"},{"UnitPrice":0.5,"Quantity":1.0,"ProductName":"Eraser"}],"invoiceNumber ":1},{"totalPrice":11.5,"statementDate":"2011-10-04T16:58:54.858Z","lineItems":[{"UnitPrice":6.0,"Quantity":1.0,"ProductName":"Notebook"},{"UnitPrice":2.5,"Quantity":1.0,"ProductName":"Ruler"},{"UnitPrice":1.5,"Quantity":2.0,"ProductName":"Pen"}],"invoiceNumber ":2}]}';
        fromJSON json2Apex =fromJSON.parse(input);
        system.debug(json2apex);
    }
}

inner class:
public class fromJSON{
    public cls_invoiceList[] invoiceList;
    public class cls_invoiceList {
        public decimal totalPrice;    
        public Datetime statementDate;    
        public cls_lineItems[] lineItems;
        public Integer invoiceNumber ;    
    }
    class cls_lineItems {
        public decimal UnitPrice;    
        public Decimal Quantity;    
        public String ProductName;    
    }
    public static fromJSON parse(String json){
        return (fromJSON) System.JSON.deserialize(json, fromJSON.class);
    }
   
}

here unn

 
bretondevbretondev
Why do you put invoiceNumber with space?
If you write "invoiceNumber":2 instead of "invoiceNumber ":2  ,  it should work
Narender Singh(Nads)Narender Singh(Nads)
Hi Neelofer,
Property names in your JSON object must be same as the data variables you define in your class, otherwise you will get a NULL for the unmatched name property.