想象一下,我有这个:
[
{"id":1, "name":"bla", "other":"aaaa"},
{"id":2, "name":"ble", "other":"eeee"},
{"id":3, "name":"bli", "other":"iiii"},
]
我想在someview.html.erb
中看到这一点Id:1
name:Bla
other:aaaa
Id:2
name:Ble
other:eee
...
当我说JSON时,我的意思是我不知道对象属性。我只是想自动格式化JSON。
答案 0 :(得分:1)
试试这个:
require 'JSON'
require 'yaml'
x = '[
{"id":1, "name":"bla", "other":"aaaa"},
{"id":2, "name":"ble", "other":"eeee"},
{"id":3, "name":"bli", "other":"iiii"}
]'
puts JSON.parse(x).to_yaml