user7047891 user7047891 - 1 month ago 14
Groovy Question

How to iterate below json in grails gsp page to get each correspondance label and value

[{"label":"AAA","value":0},{"label":"BBB","value":0},{"label":"CCC","value":0}]

Answer

You have to parse it in the server-side:

// Parse the JSON
def list = new JsonSlurper().parseText(jsonString)

Then send it to your gsp and iterate as a regular map

<g:each in="${list}">
    <p>Label: ${it.label}</p>
    <p>Value: ${it.value}</p>
</g:each>