1. #1
    Sencha User
    Join Date
    Apr 2013
    Posts
    15
    Answers
    1
    Vote Rating
    1
    fhisg is on a distinguished road

      1  

    Default Answered: How to implement custom JSON reader

    Answered: How to implement custom JSON reader


    My ST2 app needs to consume JSON in an odd format. None of the examples in JSON and Reader docs give hints as for how to implement a custom reader.

    I have a model like so:
    Code:
    Ext.define('StationData', {
      extend: 'Ext.data.Model',
      fields: [
        {name: 'id', type: 'string'},
        {name: 'name', type: 'string'} ,
        {name: 'lat', type: 'string'},
        {name: 'long', type: 'string'},
        {name: 'foo', type: 'int'}
      ]
    });
    The JSON is like so:
    Code:
    { "66000" : // needs to be mapped to 'id'
        {
          "lat" : "nn.nnnn",
          "lon" : "nn.nnnn", // needs to be mapped to 'long'
          "name" : "Foo",
          "f" : "19", // needs to be mapped to 'foo'
          ...
        },
      "66010" : 
       {....
    How do I go about this?

  2. Extend the Json reader and use the getResponseData method

    Code:
    Ext.define('MyReader', {
        extend : 'Ext.data.reader.Json',
        alias : 'reader.myreader',
    
        getResponseData : function(response) {
            var data = this.callParent([response]);
    
            //do stuff here
    
            return data;
        }
    });

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,801
    Answers
    3467
    Vote Rating
    834
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Extend the Json reader and use the getResponseData method

    Code:
    Ext.define('MyReader', {
        extend : 'Ext.data.reader.Json',
        alias : 'reader.myreader',
    
        getResponseData : function(response) {
            var data = this.callParent([response]);
    
            //do stuff here
    
            return data;
        }
    });
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi