【发布时间】:2018-06-13 23:12:38
【问题描述】:
我正在尝试使用 Jbuilder 从 json 数组中提取一些 json 对象,就像这样
irb> photos = [{"album"=>{"created_time"=>"123", "name"=>"hello"}, {"album"=>{"created_time"=>"123", "name"=>"hello2"},........]
irb> json = Jbuilder.new
irb> json.photos photos do |photo|
irb* json.created_time photo.album.created_time
irb* end
nomethoderror: undefined method 'album' for Hash:0x65...>
或者使用我得到的to_json字符串转换为json字符串
nomethoderror undefined method 'map' for String:0x83....>
我需要的只是其中的数据,因此我可以将每组 json 结果保存在用户对象中
我之前没有使用过 json 以及如何操作它,它在 Jbuilder 自述文件here 中解释了如何在模型中使用 Jbuilder,但我终生无法理解它。我试图玩弄这个例子,但它不起作用。
【问题讨论】:
标签: ruby-on-rails json ruby jbuilder