Hi everyone,
I'd
prefer JSON.parse() but in most case i have to fall back on
XML()
for example given a list
alist=
["it's
ok","I'm
late"]
If an AJAX
function returns something of the form:
return
json.dumps(dict(alist=alist,
astring='abcd'))
then JSON.parse() can cope with it
howewer if it
returns a 'hybrid' type like:
return dict(astring='abcd', ajson=json.dumps(alist))then the json part can only be decoded by XML()
Is this what's expected ? Or do i miss something ?
third option would be 'very deep snorkeling'
from json import dumps as jdumps
def abtest():
alist = ["it's ok","I'm late"]
return dict(stra='abcd', obj=jdumps(alist))
{{extend 'layout.html'}}
<h1>Ceci est le modèle test/abtest.html </h1>
<h1 id='result'>
RESULT
</h1><script>
var o= "{{=obj}}";
var po = JSON.parse(o);
console.log(po);
jQuery("#result").html(po);
</script> return dict(stra='abcd', obj=alist) # No JSON conversion needed here.
View:<script>
{{=ASSIGNJS(o=obj)}}
...
The ASSIGNJS helper will handle everything.It has been around for more than one year. It is an oversight that it is not in the book.