1

I would like to know how to parse this URL into readable JSON format with jQuery on a html page.

  • 3
    There are lots of tutorials online on how to do this. Please show what you have tried. SO isn't intended to just dump a bunch of data in and get code back. you are expected to do basic research yourself and when you have problems with live code post that – charlietfl Apr 07 '15 at 00:05
  • What URL? Please include all relevant information and code in the question itself. – Jon P Apr 07 '15 at 00:30

3 Answers3

1

You can use the $.getJSON() function in jQuery. This writes the object in the console. It is human readable. And you can manipulate anyway you want with javascript.

$.getJSON( "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=a0b2a6ee7f4de028004b9ce7e4a29f42&format=json", function(data) {
    console.log(data);
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
BassMHL
  • 8,523
  • 9
  • 50
  • 67
1

If you really need to parse json into html, use JSON.stringify()

$.getJSON( "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=a0b2a6ee7f4de028004b9ce7e4a29f42&format=json", function(data) {
    $("div").text(JSON.stringify(data))
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>
DrKey
  • 3,365
  • 2
  • 29
  • 46
0

Per Converting an object to a string

var o = {a:1, b:2};
console.log(o);
console.log('Item: ' + o);
console.log('Item: ', o);  

Output:

Object { a=1, b=2}           // useful
Item: [object Object]        // not useful
Item:  Object {a: 1, b: 2}   // Best of both worlds! :)

So what class was this homework assignment for? What is your specific task? Hint: we're going to let you get the data from the feed and store it into a javascript object variable, on your own...

Community
  • 1
  • 1
zipzit
  • 3,778
  • 4
  • 35
  • 63