Tuesday, 15 March 2011

jquery - How to parse JSON in a grails controller -



jquery - How to parse JSON in a grails controller -

i'm submitting form via jquery , i'm sending json object along submission. i'm doing so:

console.log(jsonobject) $.ajax({ type: "post", url: "/myapp/mycontroller/save", data: jsonobject, success: '', datatype: 'json' });

the console.log output looks this:

object {test: object, test2: object} test: object red: "off" green: "off" yellow: "off" test2: object red: "on" green: "on" yellow: "off"

in controllers save action right have

def save() { println params }

which prints this:

[test2[red]:on, test[green]:off, test2[yellow]:on, test2[red]:off, test[green]:off, test[yellow]:off, action:save, controller:mycontroller]

question

how can access jsonobject , parse in save()

you can access object:

params.test.red (which "off")

jquery grails groovy

No comments:

Post a Comment