Ruby 1.9.3 和 Rails 3.2.2 序列化哈希无法反序列化



基本上,我将1.8.7@rails2应用程序升级到1.9.3@rails3.2

尝试在序列化哈希上使用.each_pair时,我最终得到

syntax error, unexpected ',', expecting keyword_end
       @measure.coefficients.each_pair |key, value|

当尝试访问 rails 控制台以加载该measure.coefficients时,它给了我一个字符串。 如果我按照以下答案的指示尝试在"心理"或"syck"中运行YAML.load(serialized_string)轨道错误,无法解析 YAML

我最终得到了

ArgumentError: syntax error on line 21, col 5: `'
from /Users/user/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/syck.rb:135:in `load'

使用"心理"引擎时的结果类似。 有什么线索吗?

下面是字符串格式的哈希示例:

"--- !map:HashWithIndifferentAccess n"1092": ""n"869": ""n"1039": ""n"2492": ""n"1389": ""n"1200": ""n"600": ""n"1928": ""n"1767": ""n"1498": ""n"899": ""n"711": ""n"1124": ""n"1312": ""n"1500": ""n"900": ""n"1152": ""n"1232": ""n"1340": ""n"1420": ""n"123"

当您实际打印该值时,它会产生:

--- !map:HashWithIndifferentAccess 
"1092": ""
"869": ""
"1039": ""
"2492": ""
"1389": ""
"1200": ""
"600": ""
"1928": ""
"1767": ""
"1498": ""
"899": ""
"711": ""
"1124": ""
"1312": ""
"1500": ""
"900": ""
"1152": ""
"1232": ""
"1340": ""
"1420": ""
"123

这显然不是有效的 YAML,因为它以未终止的字符串结尾。

最新更新