Simplejson does not shun a single quote on the application engine server

I am trying to create a properly formatted json object for use in javascript. I tried simplejson.dumps (string), but it behaves differently on my local machine (in the python shell) and on the server (the google engine is running). For example, locally I will get:

>>> s= {u'hello': u"Hi, i'm here"}
>>> simplejson.dumps(s)
'{"hello": "Hi, i\'m here"}'

which looks good. But when I run it on the server, I get

{"hello": "Hello, I'm here"}

where the single quote is not escaped, which causes an error in my javascript.

Finishing secondary string.replace("'", r"\'"), does anyone have any suggestions? I am at a loss and have spent a lot of time trying to figure it out ...

+3
2

, repr .

>>> s= {u'hello': u"Hi, i'm here"}
>>> simplejson.dumps(s)
'{"hello": "Hi, i\'m here"}'
>>> print simplejson.dumps(s)
{"hello": "Hi, i'm here"}

, Python repr -, , . , dumps.

+2

JSON , , , :

>>> print simplejson.dumps(s)
{"hello": "Hi, i'm here"}

, javascript - - .

+1

Source: https://habr.com/ru/post/1773290/


All Articles