0
我想将一个对象序列化成JSON,然后通过rabbitmq通过线路发送它,然后反序列化它。在ruby中通过rabbitmq序列化和反序列化对象
我有以下的对象,我连载:
lead = Lead.new
lead.company = 'some company'
operation = proc{ AMQP::Exchange.default.publish(
lead.to_json,
:routing_key => header.reply_to,
:correlation_id => header.correlation_id
)}
在另一边,我想descerialise这样的对象:
callback_queue.subscribe do |header, body|
puts "received #{body.inspect}"
lead = ActiveSupport::JSON.decode body
puts lead.company #NoMethodError: undefined method `company' for #<Array:0x6fe03f3b>
的JSON是奇怪的数组3个哈希,看起来像这样。
[{\"created_at\":null,\"email\":\"[email protected]\",\"id\":null,\"lead_id\":null,\"updated_at\":null},{\"created_at\":null,\"email\":\"[email protected]\",\"id\":null,\"lead_id\":null,\"updated_at\":null}]"
任何人都可以看到我做错了什么吗?
http://stackoverflow.com/questions/4464050/ruby-objects-and-json-serialization-without-rails –
我的问题是,我无法解码对象。我不明白为什么对象不能正确解码。 – dagda1