I want to display JSON result in HTML table using plain JavaScript without using JQuery or any other libraries, I have JSON response like below:
{
"topalbums": {
"album": [
{
"name": "Konvicted",
"playcount": "61503",
"mbid": "13141107-58e2-4984-bb90-55aa59fc03f6",
"url": "http://www.last.fm/music/Akon/Konvicted",
"artist": {
"name": "Akon",
"mbid": "1138a764-2212-4d0a-b02d-0dc14df91e08",
"url": "http://www.last.fm/music/Akon"
},
"image": [
{
"#text": "http://userserve-ak.last.fm/serve/34s/55550849.png",
"size": "small"
},
{
"#text": "http://userserve-ak.last.fm/serve/64s/55550849.png",
"size": "medium"
},
{
"#text": "http://userserve-ak.last.fm/serve/126/55550849.png",
"size": "large"
},
{
"#text": "http://userserve-ak.last.fm/serve/300x300/55550849.png",
"size": "extralarge"
}
],
"@attr": {
"rank": "1"
}
},
I want to access the first image URL as seen above, I tried using it like below but did not worked:
var text;
for (i = 0; i < json.topalbums.album.length; i++)
{
text += json.topalbums.album[i].name + " "+json.topalbums.album[i].image[1].#text+"<br>";
}
Can anyone suggest some solution?.