1. #1
    Sencha User
    Join Date
    Feb 2008
    Posts
    12
    Vote Rating
    0
    kalbster is on a distinguished road

      0  

    Default Unable to parse JSON returned by Server.

    Unable to parse JSON returned by Server.


    I cannot seem to make a simple json call work with Ext.data.Store. I have been using ExtJS for years, and have no problems using JsonStore, etc. Perhaps I am missing something with the Touch library. I am using the 0.99 Beta.

    Here is my code.

    Code:
    Ext.setup({
    
        onReady : function() {
    		
    
     	var cStore = new Ext.data.Store({
                autoLoad: true,
                proxy: {
                    type: 'ajax',
                    url: '/json/communities.json.cfm',
                    reader: {
                        type: 'json',
                        root: 'communities',
    		    totalProperty: 'results'
                    }
                }
    	 ,fields: ['atm_id', 'atm_description']
            });
            		
    
    	
        }
    	
    });
    Here is the json that is returned. I have reduced it to one result thinking that there may have been a problem with my data.

    Code:
    {communities:[{atm_code:'ALL',atm_description:'ALL Communities'}],success:true,results:1}

    Here is the error that is thrown:

    Code:
    Uncaught Ext.data.JsonReader.getResponseData: Unable to parse JSON returned by Server.
    Ext.data.JsonReader.Ext.extend.getResponseDatasencha-touch-debug.js:9169
    Ext.data.Reader.Ext.extend.readsencha-touch-debug.js:8874
    (anonymous function)sencha-touch-debug.js:8182
    Ext.data.Connection.Ext.extend.onCompletesencha-touch-debug.js:16703
    Ext.data.Connection.Ext.extend.onStateChangesencha-touch-debug.js:16650
    (anonymous function)sencha-touch-debug.js:3175
    Thanks for any help/advice. I apologize in advance if there is a getting started guide for extjs users that I missed. I do look forward to extending my applications with Sencha Touch. Thanks!

  2. #2
    Sencha User
    Join Date
    Aug 2010
    Posts
    17
    Vote Rating
    0
    nicholasgins is on a distinguished road

      0  

    Default


    Not valid JSON. This is valid. {"communities":[{"atm_code":"ALL","atm_description":"ALL Communities"}],"success":true,"results":1}
    Validate your JSON => http://www.jsonlint.com/

  3. #3
    Sencha User
    Join Date
    Feb 2008
    Posts
    12
    Vote Rating
    0
    kalbster is on a distinguished road

      0  

    Default Thanks

    Thanks


    Sorry about that. I had taken the quotes out when trying to debug. The response works correctly now.

  4. #4
    Sencha User
    Join Date
    Feb 2008
    Posts
    12
    Vote Rating
    0
    kalbster is on a distinguished road

      0  

    Default Just curious, why does ExtJs allow this?

    Just curious, why does ExtJs allow this?


    It is interesting to note the EXTJS does not have a problem with the json example I provided. For example:

    Code:
    var communitesJSON =   new Ext.data.JsonStore({
    	storeId:'communitesJSON',
    	data: [{"communities":[{atm_code:'ALL',atm_description:'ALL Communities'},
    {atm_code:'COM-VI',atm_description:'Vascular / Interventional'}],"success":true,"results":2}],
    	root: 'communities',
    	fields: ['atm_code', 'atm_description']
    	});
    parses correctly and without error in ExtJS. I am just curious about the difference. Moving forward I will ensure that my JSON is formatted correctly.

  5. #5
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,920
    Vote Rating
    632
    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


    Depends on the browser and Ext version. In later versions of Ext, we use the native browser JSON parsing methods where they are available. WebKit requires that all property names be quoted, amongst other things.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  6. #6
    Sencha User
    Join Date
    Dec 2009
    Posts
    13
    Vote Rating
    0
    vikinko is on a distinguished road

      0  

    Default Unable to read JSON from PHP to execute JS function

    Unable to read JSON from PHP to execute JS function


    I seem to have a similar problem with reading JSON formatted text and would REALLY appreciate someone's help. The objective is to dynamically load modules for the Desktop application, but with the below code it doesn't appear to work.

    PHP code
    $member_check=$_SESSION['login_member'];

    $sql="SELECT mod_referrals, mod_mileage FROM modules WHERE email='$member_check'";
    $query=mysql_query($sql);
    $result=mysql_fetch_object($query);
    $module_referrals=$result->mod_referrals;
    $module_mileage=$result->mod_mileage;

    if($module_referrals>0)
    {
    $modules[0]="Referral";
    }
    if($module_mileage>0)
    {
    $modules[1]="Mileage";
    }
    echo '{"mod":'.json_encode($modules).'}';


    JS Code
    getModules : function(){
    var moduleAccess = new Ext.data.JsonStore({
    url: 'library/modules.php',
    root: 'mod',
    nocache: true,
    autoLoad: false,
    fields: ['mod_name']
    });
    moduleAccess.load();
    moduleAccess.on('load', function(){
    MyDesktop.modules = [];
    for(i=0; i< moduleAccess.getCount(); i++){
    var module = eval(moduleAccess.getAt(i).get("mod_name"));
    MyDesktop.modules.push(module);
    }
    return MyDesktop.modules;
    });
    }

    JSON
    {"mod":["Referral","Mileage"]}
    Last edited by vikinko; 5 Nov 2010 at 10:11 PM. Reason: added JSON output

  7. #7
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,920
    Vote Rating
    632
    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


    It's not in the correct format.

    With that config, the data should be:

    Code:
    {
        "mod": [{
            "mod_name": "Referral"
        },{
            "mod_name": "Mileage"
        }]
    }
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  8. #8
    Sencha User
    Join Date
    Dec 2009
    Posts
    13
    Vote Rating
    0
    vikinko is on a distinguished road

      0  

    Default


    Thank you, Evan... unfortunately, as a beginner I am still a bit confused on how to construct the JSON, in order to produce the desired output.

    Moreover, I have tried manually "producing/echoing" the format that you specified above in the PHP code, via:

    echo "{\"mod\":[{\"mod_name\": \"Referral\"},{\"mod_name\": \"Mileage\"}]}";

    which produces the following JSON output:

    {"mod":[{"mod_name": "Referral"},{"mod_name": "Mileage"}]}

    but I am still unable to view the Desktop menu/modules.

    Your expertise is much appreciated.

    Cheers,
    Vic

  9. #9
    Sencha User
    Join Date
    Jul 2011
    Location
    Colorado
    Posts
    1
    Vote Rating
    0
    cburlingame is on a distinguished road

      0  

    Default I too, have the same issue.. been trying to figure this one out a while

    I too, have the same issue.. been trying to figure this one out a while


    The json output from server:
    {"root":[{"CODE":"00101101110","Field_A":"AAAAA","DESC":"Disc Set","TYPE":"Euro","ADDRESS":"1234 Some St","CITY":"ADAMS","STATE":"MN","ZIPCODE":"55555","LASTUPD":"10/24/2006"}],"totalproperty":1.0,"success":true}

    Here is my store(EXT 4 MVC setup):
    Ext.define('Clli.store.clliStore', {
    extend: 'Ext.data.Store',
    model: 'Clli.model.clliModel',
    alias: 'widget.clliStore',
    requires: 'Clli.model.clliModel',
    proxy: {
    type: 'ajax',
    url: '/railo-3.2.3.000/Ztool/com/controller/zController.cfc',
    extraparams: {
    method: 'getReportData'
    },
    reader: {
    type: 'json',
    root: 'root',
    successProperty: 'success',
    totalProperty: 'totalproperty'
    }
    },
    autoLoad: true
    });
    Anyone know what I am missing here? I know that there are multiple formats of accepted json dependant on what is used.. but to me this looks like valid json, however, ext is just complaining away

    Thanks in advance for any input!

  10. #10
    Sencha User
    Join Date
    Mar 2013
    Posts
    11
    Vote Rating
    1
    tomyuen007 is on a distinguished road

      0  

    Default


    I am trying to read a json file from Sencha Architect Sencha Touch 2 application but getting "MyJsonReader unable to read data. Open in Browser: data/cars.json". I am just trying to read the cars.json file which comes with the example. I posted the question a few times in the Sencha Forum but that did not point me to anywhere that can help me. The odd thing is that I was able to read the cars.json file from the ExtJS app in Sencha Architect.


    I think Sencha Architect is the a good product but if I cannot even read a simple json file, I am not convinced it will help me do our system.


    Can someone help me so that I can move to the next step in my evaluation process.


    Best regards

Similar Threads

  1. Unable parse JSON string
    By Jaeger in forum Sencha Touch 1.x: Discussion
    Replies: 10
    Last Post: 24 Aug 2010, 11:32 PM
  2. Replies: 4
    Last Post: 15 Mar 2010, 3:50 AM
  3. Opening a pdf returned from server
    By MH61 in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 3 Sep 2009, 11:06 AM
  4. Dynamic grid from returned server respose object
    By Mango_lier in forum Ext 2.x: Help & Discussion
    Replies: 6
    Last Post: 31 Oct 2007, 8:08 AM
  5. loading grid with JSON object returned from server
    By Tina G in forum Ext 1.x: Help & Discussion
    Replies: 13
    Last Post: 17 Oct 2007, 4:54 AM

Thread Participants: 5