我想使用 Jbuilder 对以下 JSON 对象进行编码。怎么做?
"should" : [
{
"term" : { "tag" : "wow" }
},
{
"term" : { "tag" : "elasticsearch" }
}
]
最佳答案
试试 child!方法,例如
output = Jbuilder.encode do |json|
json.should do
json.child! do
json.term { json.tag "wow" }
end
json.child! do
json.term { json.tag "elasticsearch" }
end
end
end
puts output
输出:
{"should":[{"term":{"tag":"wow"}},{"term":{"tag":"elasticsearch"}}]}
关于json - Jbuilder:如何对哈希数组进行编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20472627/