Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google应用程序引擎Python simplejson转义?_Python_Google App Engine_Simplejson - Fatal编程技术网

Google应用程序引擎Python simplejson转义?

Google应用程序引擎Python simplejson转义?,python,google-app-engine,simplejson,Python,Google App Engine,Simplejson,例如,GAE上的django.utils.simplejson版本在执行js=json.dumps(我的dict\u w\u strings\u w\u newline\u和\u slash)时会转义“/”字符,而不是“\n”,这在我尝试将json.loads(js)加载到其他地方的客户端时会导致问题 有没有关于如何解决问题的建议?字符串是base64编码的数据,这些数据会因此而损坏 我尝试了SDK附带的simplejson版本(Django 0.96和1.2)和转义“\n”: >>

例如,GAE上的django.utils.simplejson版本在执行
js=json.dumps(我的dict\u w\u strings\u w\u newline\u和\u slash)
时会转义“/”字符,而不是“\n”,这在我尝试将
json.loads(js)
加载到其他地方的客户端时会导致问题


有没有关于如何解决问题的建议?字符串是base64编码的数据,这些数据会因此而损坏

我尝试了SDK附带的simplejson版本(Django 0.96和1.2)和转义“\n”:

>>> simplejson.dumps({'foo': '\n'})
'{"foo": "\\n"}'


我的同事建议:

如果json.encoder.ESCAPE_DCT.get('/')!='/':
json.encoder.ESCAPE_DCT['/']='/'

这是很好的工作。

在GAE上的实际版本没有这样做。而“/”实际上对我来说是个更大的问题。现在我在想,可能是
self.response.out.write
\/
或我想要
/
的时候取消了
\/
的转义。
Google App Engine/1.5.1
Python 2.5.2 (r252:60911, Mar 17 2011, 15:16:30) 
[GCC 4.3.1]

>>> from django.utils import simplejson
>>> simplejson.dumps({'foo': '\n'})
'{"foo": "\\n"}'
>>> simplejson.dumps('foo/bar')
'"foo\\/bar"'