关于RubyonRails:将JSON解析的字符串恢复为JSON

Revert a Json parsed string to Json

本问题已经有最佳答案,请猛点这里访问。

我在Ruby on Rails工作。我有一个这样的JSON字符串

1
"{"user":{"email":"blah@blah.com","name":"blah Test 1051","mobile":"9999999999","dob":"00/00/0000","street":"somewhere","state":"something","city":"nowhere","pincode":"50000","Event_Code":"e0031"}}"

我需要像这样把它转换成JSON哈希

1
{"user"=>{"email"=>"[email protected]","name"=>"blah Test 1051","mobile"=>"9999999999","dob"=>"00/00/0000","street"=>"somewhere","state"=>"something","city"=>"nowhere","pincode"=>"50000","Event_Code"=>"e0031"}}


1
2
require 'json'
h = JSON.parse string

此链接将帮助您..

https://hackhands.com/ruby-read-json-file-hash/


1
JSON.parse"{"user":{"email":"blah@blah.com","name":"blah Test 1051","mobile":"9999999999","dob":"00/00/0000","street":"somewhere","state":"something","city":"nowhere","pincode":"50000","Event_Code":"e0031"}}"

查看http://apidock.com/ruby/json/parse了解更多参考信息