这是的正常行为
render。当您提供
render无括号的参数时
render model as JSON
进行隐式调整以设置
content-typeto
text/json。但是,在后一种情况下,你已经在不知不觉中进行的
render使用像括号[标记的第一支撑后
render品牌呈现正常使用的
render()]
render ((products) ? [products:products] : [products:"No products found"]) asJSON。
在上述情况下,你必须在指定的参数传递给
render提了
contentType,
text或者
model,
status等于是为了使在线控制逻辑JSON在浏览器/查看您所要做的象下面这样:
render(contentType: "application/json", text: [products: (products ?: "No products found")] as JSON)
您还可以使用
content-type作为
text/json。我更喜欢
application/json。
更新
最简单的方法:
render([products: (products ?: "No products found")] as JSON)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)