Marshal.load a string
I'm trying to deserialize a hash from a string:
names = '{foo:"bar"}'
@names_hash = Marshal开发者_StackOverflow社区.load(names)
but I get a TypeError:
TypeError: incompatible marshal file format (can't be read)
format version 4.8 required; 123.111 given
According to the docs Marshal.load should accept a String. Why am I getting the error?
Here's the output of an IRB session:
irb(main):005:0> a = {"foo" => "bar"}
=> {"foo"=>"bar"}
irb(main):006:0> Marshal.dump(a)
=> "\004\b{\006\"\bfoo\"\bbar"
What you're doing looks more like JSON to me, than Marshaling.
精彩评论