2011-06-22 143 views
2

GAE上的django.utils.simplejson版本是例如在執行js = json.dumps(my_dict_w_strings_w_newline_and_slash)時轉義「/」字符,但不是「\ n」,當我嘗試在其他位置的客戶端中嘗試json.loads(js)時,會導致問題。Google App Engine Python simplejson轉義?

關於如何整理解決方案的任何建議?這些字符串是base64編碼的數據,因此被破壞。

回答

0

我的同事曾建議:

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

這是工作NIC伊利。

3

我試着隨SDK(Django的0.96和1.2)的simplejson版本和兩個逃跑 '\ n' 的

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

而且在http://shell.appspot.com/

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"' 
+0

GAE上的實際版本沒有這樣做。實際上,「/」對我來說是一個更大的問題。 –

+0

奇怪。我在http://shell.appspot.com/上試過了,它也逃脫了。 – moraes

+0

嗯。現在我想可能是'self.response.out.write',當我只想'''時,''將'\\ /'轉換爲'\ /'或什麼的。 –