`
leon1509
  • 浏览: 533242 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

关于Grails输出JSON的总结

阅读更多

1.

 

def oList = [total:0, rows:[]]
oList['total'] << Role.count()
oList['rows'] << Role.list(params)

render oList as JSON

 

输出结果:

{"total":0,"rows":[[]]}

 

2.

def om = [
	success : false,
	info : '',
	data : [],
	error : ''
]

om.success = true
om.data << [total: Role.count(), rows:Role.list(params)]

render om as JSON

 

输出结果:

{"success":true,"info":"","data":[{"total":1,"rows":[]}],"error":""}

 

3.

def om = [
	success : false,
	info : '',
	data : [],
	error : ''
]
om.success = true
om.info = "数据加载成功!"
om.data << [total: Role.count(), rows:[Role.list(params)]]
println om.data as JSON

 输出结果:[{"total":1,"rows":[[]]}]

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics