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