grails处理json数据
- 作者: 小宝很社会
- 来源: 51数据库
- 2022-08-17
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
}
}
推荐阅读
