Grails. JSON. his methods?
I was up all night looking for information on how to use JSON
in Grails
. And I found the information that in JSON closure
, we can use only one method - array
- no other. is it true?
and next small question:
i find here: http://www.jiramot.info/mini-guide-to-rendering-json-with-grails example:
render(contentType:‘text/json’){
collection{
pair(name:‘value’)
pair(name:‘value1′)
}
}
开发者_JS百科Will be rendered as:
{collection:[{"name":"value"},{"name":"value1"}]
but when i try do it, i have this result:
{"collection":{"pair":{"name":"value1"}}}
What conclusion can we do? i do some wrong or wrong example on site?
try
render(contentType:‘text/json’){
collection {
array {
pair(name:"value")
pair(name:"value1")
}
}
}
JSON rendering in Grails is much easier...
def foobar = [ fooArray: [ 1, 2, 3 ], bar: [ b: "bbb", a: "aaa", r: "rrr" ] ]
render foobar as JSON
results in
{"fooArray":[1,2,3],"bar":{"b":"bbb","a":"aaa","r":"rrr"}}
Just create an appropriate Groovy structure and render
it as JSON
.
精彩评论