使用 Grails 在服务器端获取 JSON 数据 [英] Getting JSON data on server side with Grails

查看:15
本文介绍了使用 Grails 在服务器端获取 JSON 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦我将 JSON 数据发布到 Grails 中的 url,我如何才能访问控制器内部的数据?

Once I post JSON data to a url in Grails, how can I get access to that data inside of the controller?

推荐答案

Grails 自动解析/解组 JSON,您可以通过控制器中的 request.JSON 访问它.返回的对象类型为 JSONObject 从而允许以地图样式访问属性.也可以直接使用这个 JSONObject 进行数据绑定:

Grails automatically parses/unmarshals the JSON and you can access it via request.JSON in your controller. The object returned is of type JSONObject and thus allows map-style access to the properties. You can also directly use this JSONObject for data binding:

def jsonObject = request.JSON
def instance = new YourDomainClass(jsonObject)

这篇关于使用 Grails 在服务器端获取 JSON 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆