PDA

View Full Version : Ext.decode() fails on Python's 'False'



ZooKeeper
30 Oct 2007, 4:34 AM
Json, formed by Python
{'msg': 'hey', 'success': False}



Ext.Ajax.request({
method: 'post',
callback: function(opts,suss,resp){
var jsonData = Ext.decode(resp.responseText);
if (!jsonData.success) {
Ext.MessageBox.alert('Error', jsonData.msg);
} else {
// Do something clever
}
}




Firebug:
False is not defined
return eval("(" + json + ')');

extall:
this.decode = function(json){
return eval("(" + json + ')');
};


It appears that Ext expects JS-like false

jay@moduscreate.com
30 Oct 2007, 5:01 AM
have you read: http://extjs.com/learn/Manual:Core:Ext.Ajax ?

BernardChhun
30 Oct 2007, 5:46 AM
what JSON library are you using ZooKeeper? Mine works as expected and turns the Python False into JS false:


bernard@ubuntu-bernard:~$ python
Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> d = {"asd" : False}
>>> json.write(d)
'{"asd":false}'

ZooKeeper
30 Oct 2007, 1:57 PM
Thanks, just me being dumb.
simplejson does the trick. Thanks for feedback though, not that offten you can see it here...

BernardChhun
31 Oct 2007, 4:08 AM
Thanks, just me being dumb.
simplejson does the trick. Thanks for feedback though, not that offten you can see it here...

:-? what do you mean? people won't answer to you?

anyways, us pythonic folks gotta help each other since we're not as crowded as the PHP folks ~o)