1

I'm trying to parse some simple JSON data and pull out certain parts to display as HTML. All is going well apart from my Last.fm JSON data has a child of recenttracks.track.artist_text

The text isn't being translated or picked up properly and (as I'm new to this) cannot figure out why? The reason I believe is something to do with the underscore _ before the last child.

Everything is working well apart from this.

<script type="text/javascript">
$.getJSON("http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=foo&api_key=bar&format=json&limit=1", function(json) {
  alert("JSON Data: " + json.recenttracks.track.artist._text);
});
</script>

Any ideas what i'm doing wrong?

Thanks.

Alexander
  • 23,432
  • 11
  • 63
  • 73
mbklnd
  • 131
  • 1
  • 11

1 Answers1

2

Looking at the JSON that is produced, it looks like you would need to access as:

json.recenttracks.track.artist['#text']

Here I use bracket syntax to get at the last property #text. I don't see where you are getting the underscore in _text from as in the JSON it shows as #text.

Mike Brant
  • 70,514
  • 10
  • 99
  • 103