有没有办法将此字符串转换为ruby中的哈希值?

时间:2011-04-21 17:54:39

标签: ruby hash

{"table_no"=>nil, "name"=>"Kelly Shaye Gan", "account_id"=>1}

我的意思是我确定有;只花了几个小时试图搞清楚。我认为答案就在这里:Most efficient way to map a specific string into a hash in Ruby,但我不是正则表达式的专家,所以我不确定将哪个表达式插入到扫描中。

1 个答案:

答案 0 :(得分:8)

如果您确定输入始终是安全的,您可以评估它:

the_hash = eval(the_string)