grails - 在Grails中将 map 渲染为json

标签 grails

我在我的应用程序中使用Grails,但是JSON转换器有问题。

在我的 Controller 中,我有:

def myObject = [:]
myObject.key = 'value'
render ???

从 Controller 将myObject呈现为JSON的最佳方法是什么?

最佳答案

这很简单 :

render (myObject as JSON)

要么
render ([key: "value"] as JSON)

关于grails - 在Grails中将 map 渲染为json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14457340/

相关文章:

grails - Grails :(从客户端)编辑(形成:多部分)文件并将其发送回客户端

json - Ext Ajax请求未从Grails Controller 接收JSON作为response.responseText

grails - 禁止Grails自动设置关系中的值

hibernate - 为什么createAlias在连接两个域的域上不起作用?

字符串列表的 Grails 域命名查询

grails - 将Spring Security插件安装到Grails应用程序失败

grails - 多个 when/then 与 where for each other

用于日期验证的Grails最小约束

grails - GORM-暂时禁用beforeInsert事件

grails - grails View 中未显示“dateCreated”字段