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

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

问题描述

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

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


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

解决方案

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天全站免登陆