开发者

Ruby SQS Parsing Message?

Initially I sent the converted object using .to_json which gives me a string I sent this to sqs. Now i'm retrieving the message and now it's in string f开发者_开发问答orm? How do I parse it back into my inital object?

--Edit

Ruby on Rails. I'm using a library to contact sqs and send the object over. Before I send it, I convert it using .to_json. Then Now, I'm writing a backend.rb file that uses that library and receives the msg and if there is a msg i want it to convert that msg back into a @project then I plan to send this @project over to a template .erb file.


To turn a JSON string into Ruby objects, call JSON.parse like so:

require 'json'
JSON.parse( '{"foo":"bar"}' )
#=> {"foo"=>"bar"}

a = JSON.parse( '[1,2,3] )
#=> [1, 2, 3]

JSON.parse( '{"name":"Gavin","cats":["Phleep","Tessa"]}' )
#=> {"name"=>"Gavin", "cats"=>["Phleep", "Tessa"]}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜