import
grails.converters.JSON
class
User{
String nickname
Integer age
}
class
TestController{
def
listAsJson = {
def
output =
"{'nickname':'东瓜','age':'16'}"
render output
as
JSON
}
def
listAsJSON2 = {
def
output =
"{'nickname':'东瓜','age':'16'}"
render JSON.parse(output)
}
def
listAsJSON3 = {
def
user = User.
get
(
1
)
render user
as
JSON
}
def
listAsJSON4 = {
def
outputMap = [
'1'
:
1
,
'2'
:
2
]
render outputMap
as
JSON
}
}