[問題] 關於 rails 的 from_json / to_json

看板Ruby作者 (shadow)時間16年前 (2008/09/29 21:44), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/3 (看更多)
環境: Rails 2.1.0 Rails 有兩個 from_json / to_json 函式,我想利用這兩個函式將一個 物件陣列存在資料庫中,但是搞不太清楚它們的使用方式。 我有一個 class: class Foo attr_accessor :value def initialize(v) @value = v end end foo_arr = Array.new foo_arr << Foo.new(1) foo_arr << Foo.new(2) foo_json = foo_arr.to_json # => "[{\"value\": 1}, {\"value\": 2}]" 如果我想把 foo_json 重現回一個 Foo Arry, 要怎麼做呢? 謝謝 m(_ _)m -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.137.189.211 ※ 編輯: suomax 來自: 220.137.189.211 (09/29 21:45)
文章代碼(AID): #18uDl9za (Ruby)
文章代碼(AID): #18uDl9za (Ruby)