views:

29

answers:

1

I'm trying to parse a JSON response using jquery from last.fm and getting longitude and latitude values. The part of the JSON that holds those values looks like this:

"location":{"geo:point":{"geo:lat":"58.409901","geo:long":"15.563306"}

The code I got is this:

$.getJSON("http://ws.audioscrobbler.com/2.0/?method=artist.getevents&artist=familjen&api_key=xformat=json&callback=?",
 function(data){
  $.each(data.events.event, function(i,item){
   $("#menucontent").append("<br/>"+item.title + " " + item.venue.location.geo:point.geo:lat);
        });
});

Obviously the part "item.venue.location.geo:point.geo:lat" doesn't work. How do I get those values with ":" ?

+4  A: 

You can use bracket notation when identifiers can't be expressed in dot notation, it'd look like this:

item.venue.location["geo:point"]["geo:lat"]

For illustration, all of these are ways to access the same thing:

obj.thing.prop
obj.thing["prop"]
obj["thing"]["prop"]
obj["thing"].prop
Nick Craver