1. #1
    Sencha Premium Member dwwright's Avatar
    Join Date
    Oct 2012
    Posts
    5
    Vote Rating
    0
    dwwright is on a distinguished road

      0  

    Default Error parsing json data

    Error parsing json data


    I’m getting an error trying to use some json data and was wondering if anyone could help.

    When trying to load the data I’m getting the following error:

    SyntaxError: Parse error

    Source Class: http://earthquake.usgs.gov/earthquak...onP.callback71 Line 1”

    A second error comes back also “Unable to load data using the supplied configuration”, yet clicking the url the data displays in a browser.

    When trying to load the app in to a browser (IE), the console is showing:

    SCRIPT1004: Expected ';'
    hour?_dc=1355506715423&page=1&start=0&limit=25&callback=Ext.data.JsonP.callback1, line 1 character 8

    The json url is below and validates as json in JSONLint:

    http://earthquake.usgs.gov/earthquak...ojson/all/hour

    The url is from the geojson link next to All Earthquakes on this page: http://earthquake.usgs.gov/earthquakes/feed/

    I’ve tried the same configuration against a twitter json feed and it works fine. The code is trying to parse the properties data and I have tried parsing to get the data from the “features” root as well, but not had any luck.

    My code is as follows:

    //store
    Ext.define('Earthquakes.store.Feature', {
    extend: 'Ext.data.Store',

    requires: [
    'Earthquakes.model.Feature'
    ],

    constructor: function(cfg) {
    var me = this;
    cfg = cfg || {};
    me.callParent([Ext.apply({
    autoLoad: true,
    storeId: 'Feature',
    model: 'Earthquakes.model.Feature',
    buffered: false
    }, cfg)]);
    }
    });

    //model/Proxy/Reader
    Ext.define('Earthquakes.model.Feature', {
    extend: 'Ext.data.Model',

    fields: [
    {
    name: 'mag',
    mapping: 'mag'
    },
    {
    name: 'place',
    mapping: 'place'
    },
    {
    name: 'time',
    mapping: 'time'
    },
    {
    name: 'updated',
    mapping: 'updated'
    },
    {
    name: 'tz',
    mapping: 'tz'
    },
    {
    name: 'url',
    mapping: 'url'
    },
    {
    name: 'felt',
    mapping: 'felt'
    },
    {
    name: 'cdi',
    mapping: 'cdi'
    },
    {
    name: 'mmi',
    mapping: 'mmi'
    },
    {
    name: 'alert',
    mapping: 'alert'
    },
    {
    name: 'status',
    mapping: 'status'
    },
    {
    name: 'tsunami',
    mapping: 'tsunami'
    },
    {
    name: 'sig',
    mapping: 'sig'
    },
    {
    name: 'net',
    mapping: 'net'
    },
    {
    name: 'code',
    mapping: 'code'
    },
    {
    name: 'ids',
    mapping: 'ids'
    },
    {
    name: 'sources',
    mapping: 'sources'
    },
    {
    name: 'types',
    mapping: 'types'
    }
    ],

    proxy: {
    type: 'jsonp',
    url: 'http://earthquake.usgs.gov/earthquakes/feed/geojson/all/hour',
    reader: {
    type: 'json',
    root: 'properties',
    useSimpleAccessors: false
    }
    }
    });

  2. #2
    Sencha Premium Member dwwright's Avatar
    Join Date
    Oct 2012
    Posts
    5
    Vote Rating
    0
    dwwright is on a distinguished road

      0  

    Default


    Here is an archive of the project.

    project.xda

  3. #3
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,445
    Vote Rating
    129
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    Sounds like the service is returning JSON and you are using a JSON-P proxy.

    Does the earthquake service have support for JSON-P? If so make sure you are passing the correct callback key (you can configure this on the proxy).
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  4. #4
    Sencha Premium Member dwwright's Avatar
    Join Date
    Oct 2012
    Posts
    5
    Vote Rating
    0
    dwwright is on a distinguished road

      0  

    Default


    @aconran, Thanks for the reply.

    There is a jsonp feed here: http://earthquake.usgs.gov/earthquak...jsonp/all/hour

    It returns data in a function called eqfeed_callback({...})

    So I tried putting the 'eqfeed_callback' as the key, but I then get an error in Architect loading the data of:

    ReferenceError: Can't find variable: eqfeed_callback

    Source Class: http://earthquake.usgs.gov/earthquak...sonP.callback5 Line 2

  5. #5
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,445
    Vote Rating
    129
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    Quote Originally Posted by dwwright View Post
    @aconran, Thanks for the reply.

    There is a jsonp feed here: http://earthquake.usgs.gov/earthquak...jsonp/all/hour

    It returns data in a function called eqfeed_callback({...})

    So I tried putting the 'eqfeed_callback' as the key, but I then get an error in Architect loading the data of:

    ReferenceError: Can't find variable: eqfeed_callback

    Source Class: http://earthquake.usgs.gov/earthquak...sonP.callback5 Line 2
    Wow, I've never seen an API that has a fixed callback function name.

    The callbackKey configuration is to send what the name of the configuration will be. There is no direct support for what you are trying to do.

    You could override createRequestCallback or possibly just set the fixed eqfeed_callback to the freshly sent callback.

    This sort of relates to this bug filed against the framework.
    http://www.sencha.com/forum/showthre...ss-to-any-name
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  6. #6
    Sencha Premium Member dwwright's Avatar
    Join Date
    Oct 2012
    Posts
    5
    Vote Rating
    0
    dwwright is on a distinguished road

      0  

    Default


    Well the original call didn't have the function name. It validates as json, so I'm not sure if I'm doing something wrong in my setup or if there is a bug...

    Here is the original feed: http://earthquake.usgs.gov/earthquak...ojson/all/hour

  7. #7
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,445
    Vote Rating
    129
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    Well the original call would work fine if you proxy it through a webserver or some sort of application server that doesn't care about the web's cross domain restriction.
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  8. #8
    Sencha Premium Member dwwright's Avatar
    Join Date
    Oct 2012
    Posts
    5
    Vote Rating
    0
    dwwright is on a distinguished road

      0  

    Default


    Ah, so you're saying some servers don't care about the cross-domain yet some would? I was thinking this was on the receiving end that it would be restricted.

    This feed pulled in fine with everthing configured the same in the proxy and reader other than the url and root parameter...

    http://search.twitter.com/search.jso...otoboothowners

Thread Participants: 1