Getting JSON data on server side with Grails

后端 未结 2 876
一整个雨季
一整个雨季 2020-12-30 21:24

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

2条回答
  •  忘掉有多难
    2020-12-30 21:47

    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)
    

提交回复
热议问题