I’m using Grails 1.3.6. I read the following JSON into a variable …
{
"abc": {
"attr1": "value1",
"attr2": "value2"
},
"def": {
"attr1": "value1",
"attr2": "value2"
},
"ghi": {
"attr1": "value1",
"attr2": "value2"
},
...
}
If, in my controller, I’m passed a parameter referring to one part of the JSON object …
def section = params.section; // could be "abc", "def", 'ghi", ...e
How do I access that part of the JSON assuming the above gets stored into a Groovy variable named “myJSONObject”? Thanks, – Dave
If you used
JSON.parse()to create yourmyJSONObject, you can just do: