0
我以前從未注意過這種行爲,但在解析保存在cookie中的JSON編碼的字符串時,字符串看起來是url編碼的(主要症狀是空格被加號替換爲「+」 「 標誌)。JSON解析生成url編碼的字符串
基本上它是快閃消息數組(如在滑軌,我不知道,如果問題是在編碼側)所編碼的使用:
def write_flash_to_cookie
cookie_flash = {}
flash.each do |key, value|
if cookie_flash[key.to_s].nil? or cookie_flash[key.to_s].blank?
cookie_flash[key.to_s]= [value]
else
cookie_flash[key.to_s]<< value
end
end
cookies['flash']= cookie_flash.to_json
flash.clear
end
正因爲如此顯示:
我看不到我在這裏丟失的東西...
問題在於Ruby的(或者Rails在這個例子中,因爲to_json使用ActiveSupport)的cookie支持,它對URL進行了字符串編碼。迄今爲止唯一的解決方案似乎只是將RegEx替換爲「+」號。 – StrangeElement 2011-05-20 18:28:33