2010年8月27日 星期五

JSON GAE google appengine 吐血的特絑符號處理 換行符號 斜分號 等

JSON
吐血的特絑符號處理

1.換行符號:
會導致無法讀取JSON
GAE裡可在用template裡的linebreaksbr換成
2.斜分號 "\"在String裡會判斷錯,同樣導致無法讀取JSON,怪的是不見得一定會出現無法讀取的狀況,在local端做伺服時都正常,但一上線,就是掛~
在GAE裡可用urlencode先轉碼,然後輸出時,再用javascript 的 decodeURI再轉回來。

原以為如此如此就天下太平了,
但是一上線還是掛
    return urllib.quote(value) 
  File "/usr/lib/python2.6/urllib.py", line 1223, in quote 
    res = map(safe_map.__getitem__, s) 
KeyError: u'\xe3' 


urlencode轉碼失敗


然後
http://groups.google.com/group/google-appengine-python/browse_thread/thread/70b10f012ae33aed/996ecc33e7444cfc?#996ecc33e7444cfc


http://seewah.blogspot.com/2009/11/django-template-urlencode-unicode.html

上面有解,
不過還是不行,殘念~

結論就是存檔前先擋吧~
今天完全敗給 \^^/
可恥的一天