-1

I'm new in using JSON with Jquery and i ret some documentation and still cant get it to work. I need pase data using JSON from last.fm API and get artist information (summary).

Link to API with artist Cher: http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=2b35547bd5675d8ecb2b911ee9901f59&format=json

Can anybody experienced write me simple example how to use Jquery to get an artist information from last.fm ? Thank you in advance :)

Oli Řeháček
  • 53
  • 1
  • 1
  • 10

2 Answers2

1

You could start with something like

$.ajax({
  url: 'http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=2b35547bd5675d8ecb2b911ee9901f59&format=json',
  success: function(data) {
    alert(data.artist.name);
  }
})

As you can see data is in json format, so you could access its properties using the dot notation.

Alberto Zaccagni
  • 30,779
  • 11
  • 72
  • 106
  • Thank you for this, im really newbie in terms of JS and im finding things out :) Can you please show me example how to get and artist image in large size :) thank you very much. – Oli Řeháček May 21 '13 at 22:30
0

Before asking, you should make a little Google search!

$.getJSON('http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=2b35547bd5675d8ecb2b911ee9901f59&format=json', function(data) {
    var items = [];

    $.each(data, function(key, val) {
      items.push('<li id="' + key + '">' + val + '</li>');
    });

    $('<ul/>', {
      'class': 'my-new-list',
      html: items.join('')
    }).appendTo('body');
});

Directly from jQuery.getJSON -- read documentation.

Niccolò Campolungo
  • 11,824
  • 4
  • 32
  • 39
  • Thank you for this, im really newbie in terms of JS and im finding things out :) Can you please show me example how to get and artist image in large size :) thank you very much. – Oli Řeháček May 21 '13 at 22:29