将对象和值作为JSON呈现为ajax响应
我正在努力做到以下几点:将对象和值作为JSON呈现为ajax响应,json,grails,Json,Grails,我正在努力做到以下几点: render [assignedSchol:assignedSchol,scholType:scholType] as JSON assignedSchol是一个对象,scholType只是一个值。我得到一个“此处不允许地图输入错误”。有什么帮助吗?这应该可以: render(contentType: "application/json") {[assignedSchol:assignedSchol,scholType:scholType]} 这应该起作用: ren
render [assignedSchol:assignedSchol,scholType:scholType] as JSON
assignedSchol是一个对象,scholType只是一个值。我得到一个“此处不允许地图输入错误”。有什么帮助吗?这应该可以:
render(contentType: "application/json") {[assignedSchol:assignedSchol,scholType:scholType]}
这应该起作用:
render(contentType: "application/json") {[assignedSchol:assignedSchol,scholType:scholType]}
当您像使用一样使用一个衬里时,必须将转换放在大括号中,如下所示:
render ( [assignedSchol:assignedSchol,scholType:scholType] as JSON )
但我认为上面的代码以纯文本格式返回json数据,所以我通常更喜欢这样做:
render(contentType: "text/json") {
[assignedSchol:assignedSchol,scholType:scholType]
}
这为我提供了响应类型为json的json数据。当您使用一个类似于的行程序时,必须将转换放在大括号中,如下所示:
render ( [assignedSchol:assignedSchol,scholType:scholType] as JSON )
但我认为上面的代码以纯文本格式返回json数据,所以我通常更喜欢这样做:
render(contentType: "text/json") {
[assignedSchol:assignedSchol,scholType:scholType]
}
这给了我响应类型为json的json数据。谢谢,Ia实际上刚刚意识到我需要将其全部用括号括起来。。哈哈哈,我才意识到我需要用括号把这一切都括起来。。可能重复的可能重复的