22

有没有明确"text/json"指定的速记方法?

def remoteError = {     
  render( status: 500, contentType: "text/json"){
      error( exception: "a remote exception occurred")
  }
}

我尝试使用as JSON...没有返回内容,但状态码是正确的...

render( status: 500, exception: params.exception) as JSON 
4

2 回答 2

42

If you use a converter parameter to render then you cannot specify any other parameter such as status like you normally would when using gsp views. You can however set the response status prior to calling render:

response.status = 500
render([error: 'an error occurred'] as JSON)
于 2012-05-23T20:25:06.210 回答
2
render(status:500,text:(errors as JSON).toString(),contentType: 'application/json')
于 2016-03-14T01:33:22.287 回答