我想使用 Jbuilder 对以下 JSON 对象进行编码。怎么做?
"should" : [
{
"term" : { "tag" : "wow" }
},
{
"term" : { "tag" : "elasticsearch" }
}
]
我想使用 Jbuilder 对以下 JSON 对象进行编码。怎么做?
"should" : [
{
"term" : { "tag" : "wow" }
},
{
"term" : { "tag" : "elasticsearch" }
}
]
试试孩子!方法,例如
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"}}]}