When I load up the Rails console in my project, I can do this:
{}.to_json
But I can’t do this:
"{}".from_json
Even when I require the json gem first, it doesn’t work. Does a from_json method even exist?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No.
from_jsondoes not exist. If you want to get a Ruby hash from a JSON string, you can use theJSON#parsemethod. Example below:json = JSON.parse("{\"hello\": \"world\"}")the above returns
{"hello"=>"world"}