问题
I'm using Grails for my application, and I have a problem with JSON converters.
In my controller, I have:
def myObject = [:]
myObject.key = 'value'
render ???
what is optimal way to render myObject
as JSON from the controller?
回答1:
It's easy :
render (myObject as JSON)
or
render ([key: "value"] as JSON)
回答2:
Other way is :
render (contentType: 'text/json'){
array {
for(f in Person.list()){
person id: f.id, name: f.name
}
}
}
This sample render a list of Persons
来源:https://stackoverflow.com/questions/14457340/render-map-as-json-in-grails