1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    28
    Vote Rating
    0
    Larry Q is on a distinguished road

      0  

    Default Answered: What reader will work with this Array / JSON data?

    Answered: What reader will work with this Array / JSON data?


    I'm calling a RESTful web service using the jsonp proxy for this URL:

    http://fastmotorcycleservice.cloudap...svc/list/Bruno

    The data that is returned is a sort-of mix between JSON and an array. Looks like so:

    Code:
    ["Test","Hello","Bananna","Apple"]

    For the life of me, I cannot get a Reader to work with that data. I've tried using both Array and Json readers. Here's the code I'm using with an Ext.data.Store:
    Code:
       
    
        Ext.define('SearchResult', {
            extend: 'Ext.data.Model',
            config: {
                fields: [
                    {name: 'name', type: 'string'}
                ]
            }
        });
    
    
        var store = Ext.create('Ext.data.Store',{
            model: 'SearchResult',
            autoLoad: true,
            proxy: {
            type: 'jsonp',
            url: 'http://fastmotorcycleservice.cloudapp.net/FastMotorCycleListService.svc/list/Bruno',
            // reader: {
            // type: 'json',
            // root:''
            // }
            reader: {
                type: 'array',
                 exception: function(rdr, resp, err, eOpt) {
                      alert('error!');
                    }            
            }
                
            }
        });
    Any ideas what I can do to get that data format into my store? Thanks much.

  2. Just as an fyi for @"Larry Q", The array reader can read data like:

    Code:
    [
        ["field1", "field2"],
        ["foo", "bar"]
    ]

  3. #2
    Sencha User
    Join Date
    Oct 2011
    Posts
    14
    Vote Rating
    1
    Answers
    1
    7C Dev is on a distinguished road

      0  

    Default


    I am not sure if any of the predefined readers can interpret this data, so i think you're stuck writing your own.
    The format should not be too hard to parse, though; i would suggest two alternatives:
    1. extend from Json Reader, override the read method, modify the incoming string so it is valid json and let the json reader do the rest
    2. extend from Reader and implement the full API yourself, parsing the string by hand using String.split('","') to extract your tokens

    just a starting point, i am not really familiar with the reader API so maybe there probably are some more pitfalls to those alternatives..

  4. #3
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,641
    Vote Rating
    898
    Answers
    3573
    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


    Just as an fyi for @"Larry Q", The array reader can read data like:

    Code:
    [
        ["field1", "field2"],
        ["foo", "bar"]
    ]
    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.

  5. #4
    Sencha User
    Join Date
    Feb 2011
    Posts
    28
    Vote Rating
    0
    Larry Q is on a distinguished road

      0  

    Default


    Thanks for the replies. I'll try mucking around with the data string and get it into an acceptable format. Appreciate the help!

Thread Participants: 2

Tags for this Thread