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

时间:2022-07-19 15:59:08

Basically, I upgraded a 1.8.7@rails2 app to 1.9.3@rails3.2

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

When trying to use .each_pair on a serialized hash, I end up getting

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

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

When trying to access the rails console to load up that measure.coefficients, it gives me a string. Which if I try running YAML.load(serialized_string) in either "psych' or 'syck' as instructed by the following answer rails error, couldn't parse YAML

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

I end up getting

我最终得到了

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'

Similar result when using 'psych' engine. Anyclue?

使用'psych'引擎时的结果相似。 Anyclue?

Here is a sample of the hash in string format:

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

"--- !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"

1 个解决方案

#1


1  

When you actually print the value, it yields:

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

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

Which is clearly not valid YAML, as it ends with a unterminated string.

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

#1


1  

When you actually print the value, it yields:

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

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

Which is clearly not valid YAML, as it ends with a unterminated string.

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