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