01 | import grails.converters.JSON |
02 |
03 | class User{ |
04 | String nickname |
05 | Integer age |
06 | } |
07 | class TestController{ |
08 | def listAsJson = { |
09 | def output = "{'nickname':'东瓜','age':'16'}" |
10 | render output as JSON |
11 | } |
12 | def listAsJSON2 = { |
13 | def output = "{'nickname':'东瓜','age':'16'}" |
14 | render JSON.parse(output) |
15 | } |
16 | def listAsJSON3 = { |
17 | def user = User. get ( 1 ) |
18 | render user as JSON |
19 | } |
20 | def listAsJSON4 = { |
21 | def outputMap = [ '1' : 1 , '2' : 2 ] |
22 | render outputMap as JSON |
23 | } |
24 | } |