我对为什么符号版本的键在下面的例子中不起作用感到困惑。如所示,我正在使用Ruby 1.9.3。这是一个更大的应用程序的一部分,但我已经能够将其缩小到这个问题。
提前感谢您!
1.9.3-p194:002> json_sample =“ { \”this \“:\”notworking \“}“ =>“ { \”this \“:\”notworking \“}“ 1.9.3-p194:003> test_hash = JSON.parse json_sample => {“this”=>“notworking”} 1.9.3-p194:004> test_hash [“this”] =>“notworking” 1.9.3-p194:005> test_hash [:this] => nil
提前感谢您!
1.9.3-p194:002> json_sample =“ { \”this \“:\”notworking \“}“ =>“ { \”this \“:\”notworking \“}“ 1.9.3-p194:003> test_hash = JSON.parse json_sample => {“this”=>“notworking”} 1.9.3-p194:004> test_hash [“this”] =>“notworking” 1.9.3-p194:005> test_hash [:this] => nil
JSON.parse(input, :symbolize_names => true)
进行解析。 - akuhn