📜  将字符串转换为哈希 ruby 代码示例

📅  最后修改于: 2022-03-11 15:04:45.945000             🧑  作者: Mango

代码示例1
hash_as_string = 
    "{\"0\"=>{\"answer\"=>\"1\", \"value\"=>\"No\"}, 
    \"1\"=>{\"answer\"=>\"2\", \"value\"=>\"Yes\"}, 
    \"2\"=>{\"answer\"=>\"3\", \"value\"=>\"No\"}, 
    \"3\"=>{\"answer\"=>\"4\", \"value\"=>\"1\"}, 
    \"4\"=>{\"value\"=>\"2\"}, \"5\"=>{\"value\"=>\"3\"}, 
    \"6\"=>{\"value\"=>\"4\"}}"
JSON.parse hash_as_string.gsub('=>', ':')