gpt4 book ai didi

jquery - 如何在 Grails Controller 中解析 JSON

转载 作者:行者123 更新时间:2023-12-01 04:15:43 28 4
gpt4 key购买 nike

我正在通过 jQuery 提交表单,并随提交一起发送一个 JSON 对象。我这样做是这样的:

    console.log(jsonObject)
$.ajax({
type: "POST",
url: "/myapp/mycontroller/save",
data: jsonObject,
success: '',
dataType: 'json'
});

console.log 输出如下所示:

Object {test: Object, test2: Object}
test: Object
red: "off"
green: "off"
yellow: "off"
test2: Object
red: "on"
green: "on"
yellow: "off"

在我的 Controller 中,我现在保存操作

def save() {
println params
}

打印这个:

[test2[red]:on, test[green]:off, test2[yellow]:on, test2[red]:off, test[green]:off, test[yellow]:off, action:save, controller:mycontroller]

问题

如何访问 jsonObject 并在 save() 中解析它

最佳答案

您可以像对象一样访问它:

params.test.red(“关闭”)

关于jquery - 如何在 Grails Controller 中解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14963279/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com