Im having trouble with json in mako. I do this:
${ to_json( dict( a = 1, b = 2 ) ) }
where to_json is:
<%!
import simplejson as json
def to_json( d ):
return json.dumps( d )
%>
however, instead of giving me
{"a": "1", "b": "2"}
its giving me
{"a": 1, &am开发者_StackOverflow中文版p;quot;b": 2}
so mako changes the " to " somewhere
what should i be doing instead?
in contrast, heres a test script
import simplejson as json
print json.dumps( dict( a=1,b=2 ) )
output
{"a": 1, "b": 2}
edit
i changed my function to
<%!
import simplejson as json
def to_json( d ):
return "{\"a\": 1}"
%>
and it changes the " to "
, so its an issue with mako, it seems.
seems like theres an auto filter somewhere, so when i changed
${ to_json( dict( a = 1, b = 2 ) ) }
to
${ to_json( dict( a = 1, b = 2 ) ) | n }
to turn off filters, it is okay, thanks
精彩评论