Access array in Json

3

I'm trying to get a value inside the JSON but I can not get the value inside date > artist > image > [3]. # Text

{
   "artist":{
      "name":"Madeon",
      "mbid":"fa1de503-aba7-41fa-a1ed-371b3e87a717",
      "url":"https://www.last.fm/music/Madeon",
      "image":[
         {
            "#text":"https://lastfm-img2.akamaized.net/i/u/34s/38c562652b32c8d8fe612c079a8f61ca.png",
            "size":"small"
         },
         {
            "#text":"https://lastfm-img2.akamaized.net/i/u/64s/38c562652b32c8d8fe612c079a8f61ca.png",
            "size":"medium"
         },
         {
            "#text":"https://lastfm-img2.akamaized.net/i/u/174s/38c562652b32c8d8fe612c079a8f61ca.png",
            "size":"large"
         },
         {
            "#text":"https://lastfm-img2.akamaized.net/i/u/300x300/38c562652b32c8d8fe612c079a8f61ca.png",
            "size":"extralarge"
         },
         {
            "#text":"https://lastfm-img2.akamaized.net/i/u/38c562652b32c8d8fe612c079a8f61ca.png",
            "size":"mega"
         },
         {
            "#text":"https://lastfm-img2.akamaized.net/i/u/arQ/38c562652b32c8d8fe612c079a8f61ca.png",
            "size":""
         }
      ],
      "streamable":"0",
      "ontour":"1",
      "stats":{
         "listeners":"417989",
         "playcount":"7015758"
      }
   }
}

When I try to get the value with the following code:

data['artist']['image'].#text

I get undefined response, how can I get the data from #text?

    
asked by anonymous 14.07.2017 / 02:57

1 answer

5

Use the bracket notation . In addition, image is an array :

data.artist.image[3]['#text']

Click Show code snippet and then Run to see it working:

var json = {
   "data":{
      "artist":{
         "name":"Madeon",
         "mbid":"fa1de503-aba7-41fa-a1ed-371b3e87a717",
         "url":"https://www.last.fm/music/Madeon",
         "image":[
            {
               "#text":"https://lastfm-img2.akamaized.net/i/u/34s/38c562652b32c8d8fe612c079a8f61ca.png",
               "size":"small"
            },
            {
               "#text":"https://lastfm-img2.akamaized.net/i/u/64s/38c562652b32c8d8fe612c079a8f61ca.png",
               "size":"medium"
            },
            {
               "#text":"https://lastfm-img2.akamaized.net/i/u/174s/38c562652b32c8d8fe612c079a8f61ca.png",
               "size":"large"
            },
            {
               "#text":"https://lastfm-img2.akamaized.net/i/u/300x300/38c562652b32c8d8fe612c079a8f61ca.png",
               "size":"extralarge"
            },
            {
               "#text":"https://lastfm-img2.akamaized.net/i/u/38c562652b32c8d8fe612c079a8f61ca.png",
               "size":"mega"
            },
            {
               "#text":"https://lastfm-img2.akamaized.net/i/u/arQ/38c562652b32c8d8fe612c079a8f61ca.png",
               "size":""
            }
         ],
         "streamable":"0",
         "ontour":"1",
         "stats":{
            "listeners":"417989",
            "playcount":"7015758"
         }
      }
   }
};

console.log(json.data.artist.image[3]['#text']);
    
14.07.2017 / 03:12