{
success:true,
count:1,
data: [
{id:1,task:'Home Page is waiting to be promoted'}
]
}
However no matter what I tried I couldn't get the "data" array to be generated properly. The data elements within the array were being created outside the array. After enough persistence I was finally able to get it to work with this:
def tasks = .... // an array of tasks
render(builder:'json') {
success(true)
count(tasks.size())
data {
tasks.each {
data(
id: it.id,
task: it.task
)
}
}
}
Notice I had to duplicate "data" twice, once outside of the each loop and once inside. I really don't understand why, I'm just glad I figured it out and I can move on! Hopefully this will help if you are stuck with creating arrays with the JSON Builder.
4 comments:
thx for the info, exactly what I was looking for :)
I don't know if this will help:
http://www.anyware.co.uk/2005/2008/06/19/a-grails-json-builder-that-doesnt-suck/
Definitely helped me out!
My God it works!
Thanks a lot, this helped me out considerably.
Post a Comment