将对象和值呈现为 JSON 作为 ajax 响应
Render Object and Value as JSON as ajax response
我正在尝试执行以下操作:
render [assignedSchol:assignedSchol,scholType:scholType] as JSON
assignedSchol 是一个对象,而 scholType 只是一个值。我得到一个 "No map entry allowed at this place error"。有帮助吗?
这应该有效:
render(contentType: "application/json") {[assignedSchol:assignedSchol,scholType:scholType]}
当你像以前那样使用一个衬里时 你必须把转换放在大括号中 像这样:
render ( [assignedSchol:assignedSchol,scholType:scholType] as JSON )
但我认为上面的代码 returns json 数据是纯文本格式所以我通常更喜欢这样做:
render(contentType: "text/json") {
[assignedSchol:assignedSchol,scholType:scholType]
}
这给我 json 响应类型为 json 的数据。
我正在尝试执行以下操作:
render [assignedSchol:assignedSchol,scholType:scholType] as JSON
assignedSchol 是一个对象,而 scholType 只是一个值。我得到一个 "No map entry allowed at this place error"。有帮助吗?
这应该有效:
render(contentType: "application/json") {[assignedSchol:assignedSchol,scholType:scholType]}
当你像以前那样使用一个衬里时 你必须把转换放在大括号中 像这样:
render ( [assignedSchol:assignedSchol,scholType:scholType] as JSON )
但我认为上面的代码 returns json 数据是纯文本格式所以我通常更喜欢这样做:
render(contentType: "text/json") {
[assignedSchol:assignedSchol,scholType:scholType]
}
这给我 json 响应类型为 json 的数据。