0

This is the JSON

"album":[
        {
           "name":"DD Y Ponle Play",
           "artist":"Jumbo",
           "id":"2528039",
           "url":"http:\/\/www.last.fm\/music\/Jumbo\/DD+Y+Ponle+Play",
           "image":[
              {
                 "#text":"http:\/\/images.amazon.com\/images\/P\/B00005LN6S.01._SCMZZZZZZZ_.jpg",
                 "size":"small"
              },
              {
                 "#text":"http:\/\/images.amazon.com\/images\/P\/B00005LN6S.01._SCMZZZZZZZ_.jpg",
                 "size":"medium"
              },
              {
                 "#text":"http:\/\/images.amazon.com\/images\/P\/B00005LN6S.01._SCMZZZZZZZ_.jpg",
                 "size":"large"
              },
              {
                 "#text":"http:\/\/images.amazon.com\/images\/P\/B00005LN6S.01._SCMZZZZZZZ_.jpg",
                 "size":"extralarge"
              }
           ],
           "streamable":"0",
           "mbid":""
        },

And here is my function

$.each(data.results.albummatches.album , function(){

            $.each(this.image , function(){

                $('.lightbox').append('<img src="'+this["#text"]+'" />');

            });

        });

basically it all works fine, excpet that I am getting the 4 different Image sizes from the image object. However I only want to grab 1 of the sizes.

For the life of me I am having no luck specifying an id such as this[2]["#text"] or vic versa.

what am i missing? any help would be much apreciated.

Dbrandt
  • 609
  • 1
  • 6
  • 16

1 Answers1

0

Never mind. Just loopped too many times.

here is the answer:

$.each(data.results.albummatches.album , function(){

            //this worked
            $('.lightbox').append('<img src="'+this.image[3]['#text']+'" />');

        });
Dbrandt
  • 609
  • 1
  • 6
  • 16
  • actually I don't understand why you need to loop at all if you just need one image from the whole response... – TheZuck Feb 17 '13 at 07:43
  • i.e. what's wrong with $('.lightbox').append(''); – TheZuck Feb 17 '13 at 07:46
  • there are a lot more results in the object, so it needs to loop all albums. I have only attached one result block. Think of it as listing 10 images from the the first 10 search results. – Dbrandt Feb 17 '13 at 07:49