0

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>

2 Answers 2

1

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

${filter?."$i"?.value} 
Sign up to request clarification or add additional context in comments.

Comments

0

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>

2 Comments

data.value.value (no ?. needed here, as you iterate over it and it's a map, so data would be an element)
Thank you very much for your answer. It is also right, but in my case I want to iterate over another structure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.