""['opened':[111, 211, 311, 411, 1013, 1113, 1219], 'closed':[]]""
应用JSON.parse
后,我们得到:
"['opened':[111, 211, 311, 411, 1113, 1219], 'closed':[]]"
//means : omit the double `"` , from `""something""` to `"something"`
但是,预期的结果是Literal对象:
即:
{'opener': [111, 211, 311, 411, 1113, 1219], 'closed':[] }
如何达到此结果?我的意思是来自序列化Groovy Map的Javascript文字对象
@MessageMapping("/project")
@SendTo("/topic/project")
protected String project(String parameter) {
def map = ['opened':[111, 211, 311, 411, 1013, 1113, 1219], 'closed':[]]
return map.inspect()
}
答案 0 :(得分:2)
如果将Groovy映射作为JSON而不是字符串返回,则可以使您的生活更加简单,例如。
def myAction() {
def map = ['opened':[111, 211, 311, 411, 1013, 1113, 1219], 'closed':[]]
def json = map as JSON
[result: json, contentType: 'application/json']
}
然后,您可以使用类似
的内容在客户端读取JavaScript对象var someObject = ${result};
如果您通过AJAX调用您的操作,则应使用以下操作:
def myAction() {
def map = ['opened':[111, 211, 311, 411, 1013, 1113, 1219], 'closed':[]]
render map as JSON
}