tom
tom

Reputation: 449

Access JSON via a variable within a gsp

There is following JSON structure given:

"filter": {
    "1": {
        "value": "swiss"
    },
    "2": {
        "value": "google"
    }
}

How to access the variable "value" via an index variable within a gsp template like this?

<g:each in="${...}" var="data" status="i">
    ${filter?.i?.value} 
</g:each>

Upvotes: 0

Views: 360

Answers (2)

Zoidberg
Zoidberg

Reputation: 571

Is that what you are looking for? It's without index variable.

<g:each in="${filter}" var="data" status="i">
    ${data.value.value} 
</g:each>

Upvotes: 0

cfrick
cfrick

Reputation: 37073

If your "key" there is a variable you can use a GString notation like for any other property referenced by variable:

${filter?."$i"?.value} 

Upvotes: 1

Related Questions