一、傳遞json數據:
import groovy.json.JsonOutput
import grails.converters.JSON
接收:
獲取前臺傳過來的json。 使用
def jsonObject = JSON.parse(params.jsonObject)
如果是接口的話,接受json數據,使用
def jsonObject = request.JSON
返回:
方式一:
def errors = [status: 400, message:"缺少必要的參數!"]
render JsonOutput.toJson(errors)
方式二:
render ([status:400 , message:"缺少必要的參數!"]) as JSON
def clientip = request.getRemoteAddr()
def a = null as JSON
println a //null
def b = "" as JSON //報錯