Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

data-sly-list iteration for a JsonArray

Avatar

Avatar
Validate 1
Level 1
rajaram33
Level 1

Like

1 like

Total Posts

7 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
rajaram33
Level 1

Like

1 like

Total Posts

7 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
rajaram33
Level 1

03-03-2021

 
 

Hi AEM Gurus,

 

I have a JSON Array like below sample

 

 

{
"sites": {
"label": "Parent LABEL",
"mobileLabel": "Parent Mobile Label",
"items": [
{
"href": "www.google.com",
"id": "goog",
"label": "Google Search"
},
{
"href": "www.yahoo.com",
"id": "yah",
"label": "yahoo site"
},
{
"href": "www.wikipedia.com",
"id": "wiki",
"label": "wikipedia"
}
]
}
}

Now i am trying to Iterate and get the values from this JSON array using data-sly-list something like as shown in below structure

<ul data-sly-list.key="${model.jsonarray}">
<li><a  href="${key.href}">${key.label} - ${key.id}</a></li>
</ul>

I know we can iterate Arraylist or a Map object but how do I iterate a JSON array. Please suggest.

 

Regards,

Rajashankar.R

 

 

 

data-sly-list htl jsonarray
View Entire Topic

Avatar

Avatar
Validate 1
Level 7
KiranVedantam1992
Level 7

Likes

155 likes

Total Posts

157 posts

Correct Reply

46 solutions
Top badges earned
Validate 1
Establish
Give Back 3
Give Back
Boost 50
View profile

Avatar
Validate 1
Level 7
KiranVedantam1992
Level 7

Likes

155 likes

Total Posts

157 posts

Correct Reply

46 solutions
Top badges earned
Validate 1
Establish
Give Back 3
Give Back
Boost 50
View profile
KiranVedantam1992
Level 7

03-03-2021

Hi @rajaram33,

 

You can use the below code, convert JSONArray to List and pass it to sightly.

 

ArrayList<String> listdata = new ArrayList<String>();
if (jArray != null) {
for (int i=0;i<jArray.length();i++){
listdata.add(jArray.getString(i));
}
}

 

Hope this helps.

 

Thanks,

Kiran Vedantam.