GRAILS 以原子 json 值响应
GRAILS respond with atomic json values
我有一些对 return 原子值 json(user/hasPrivilege 等)有意义的操作,我希望我的回复只包含 "true" 或 "false",我还希望能够发送原始数字和字符串。我认为这些可以算作有效 json,但得到错误:
Value out of sequence: expected mode to be OBJECT or ARRAY when writing 'false' but was INIT
当 accept header 为 json 时,是否可以指示 Grails 序列化这些?
因为这些值是有效的 json 似乎 Groovy Json 输出确实将它们转换为 Json 字符串:
import groovy.json.*
JsonOutput.toJson(true)
>>> true
那么是否可以使用 JsonOutput 进行转换并使用它而不是 Grails as JSON
进行响应?
我有一些对 return 原子值 json(user/hasPrivilege 等)有意义的操作,我希望我的回复只包含 "true" 或 "false",我还希望能够发送原始数字和字符串。我认为这些可以算作有效 json,但得到错误:
Value out of sequence: expected mode to be OBJECT or ARRAY when writing 'false' but was INIT
当 accept header 为 json 时,是否可以指示 Grails 序列化这些?
因为这些值是有效的 json 似乎 Groovy Json 输出确实将它们转换为 Json 字符串:
import groovy.json.*
JsonOutput.toJson(true)
>>> true
那么是否可以使用 JsonOutput 进行转换并使用它而不是 Grails as JSON
进行响应?