1. #1
    Sencha User
    Join Date
    May 2007
    Posts
    52
    Vote Rating
    0
    dario is on a distinguished road

      0  

    Default Handling json null

    Handling json null


    Hi all
    I'm using a Store with a Json reader to get some data from the backend. Everything works fine but I get an error when some of this data has a null value.
    Here's my data

    PHP Code:

    {"licences":[{"Id":2,"LicenseKey":"123456","Point":null,"Owner":{"Id":1,"Name":"Witbit"}, "Mac":null,"Active":false},
    {
    "Id":3,"LicenseKey":"789013","Point":null,"Owner":null"Mac":null,"Active":false}]} 
    and corresponding reader:

    PHP Code:

    this
    .DS  = new Ext.data.Store(
    {
        
    reader: new Ext.data.JsonReader(
                { 
                    
    root"licences",
                    
    fields: [ "Id""LicenseKey", {name:"Owner_Name"mapping:"Owner.Name"}, "Point",  "Mac""Active" 
                })
    }); 
    When I load the data I get an error because the second license object has no owner (=null) and thus Owner.Name is not an object.
    I already found a way to make my app work but I wonder if there's way to handle data with null value...for example the reader should check if an object is null before trying to parse its members?
    Thanks in advance

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,104
    Vote Rating
    501
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Pretty much, you'd have to implement some kind of custom parser with try catch blocks.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,251
    Vote Rating
    73
    Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold

      0  

    Default


    Try:

    Code:
    {name:"Owner_Name", mapping:"Owner", convert: function(v) {return v ? v.Name : null;}}

  4. #4
    Sencha User
    Join Date
    May 2007
    Posts
    52
    Vote Rating
    0
    dario is on a distinguished road

      0  

    Default


    Thanks Condor, that perfectly worked!

Thread Participants: 2

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar