-
5 Nov 2010 3:25 AM #1
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.
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: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'] }); } });
Code:{communities:[{atm_code:'ALL',atm_description:'ALL Communities'}],success:true,results:1}
Here is the error that is thrown:
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!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
-
5 Nov 2010 4:33 AM #2
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/
-
5 Nov 2010 4:40 AM #3
Thanks
Thanks
Sorry about that. I had taken the quotes out when trying to debug. The response works correctly now.
-
5 Nov 2010 4:55 AM #4
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:
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.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'] });
-
5 Nov 2010 3:58 PM #5
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!
-
5 Nov 2010 10:09 PM #6
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
-
6 Nov 2010 12:12 AM #7
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!
-
6 Nov 2010 7:54 AM #8
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
-
22 Nov 2011 4:25 PM #9
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!
-
27 Mar 2013 6:07 PM #10
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
-
Unable parse JSON string
By Jaeger in forum Sencha Touch 1.x: DiscussionReplies: 10Last Post: 24 Aug 2010, 11:32 PM -
[CLOSED][3.0.3] DataReader.realize expects all data sent to server to be returned
By grzegorz.borkowski in forum Ext 3.x: BugsReplies: 4Last Post: 15 Mar 2010, 3:50 AM -
Opening a pdf returned from server
By MH61 in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 3 Sep 2009, 11:06 AM -
Dynamic grid from returned server respose object
By Mango_lier in forum Ext 2.x: Help & DiscussionReplies: 6Last Post: 31 Oct 2007, 8:08 AM -
loading grid with JSON object returned from server
By Tina G in forum Ext 1.x: Help & DiscussionReplies: 13Last Post: 17 Oct 2007, 4:54 AM


Reply With Quote