我正在做这样的事情:
def prods = Product.executeQuery("select category.id,category.name, avg(competition1Price), avg(competition2Price), avg(onlineCompetitionPrice) from Product group by category.id")
def output = [[:]]
prods.each { result ->
def prod = ['category_id':result[0],'category_name':result[1],'Competition1Price':result[2],'competition2Price':result[3],'onlineCompetitionPrice':result[4]]
output << prod
}
render output as JSON
我得到的输出是这样的:
[{},{"category_id":1,"category_name":"Colchones y","Competition1Price":1657.4784,"competition2Price":2071.5,"onlineCompetitionPrice":1242.5}]
我想要的是:像这样的东西..
{collection:[{"category_id":"1","category_name":"Colchones y",so on...]}
有人可以帮忙..如何操作json数据的格式..