Getting JSON data on server side with Grails

后端 未结 2 867
一整个雨季
一整个雨季 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:35

    Check out the JSON classes in Grails:

    http://grails.org/doc/latest/api/org/codehaus/groovy/grails/web/json/package-frame.html

    For example, here's how I iterate over a list of JSON records in a parameter called 'update':

        def updates = new org.codehaus.groovy.grails.web.json.JSONArray(params.updates)
        for (item in updates) {
                        def p = new Product()
            p.quantity = item.quantity
            p.amount = item.amount
            p = salesService.saveProductSales(p)
    
        }
    

提交回复
热议问题