Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing a JSON variable pre-fixed with a hash (#)

Last.fm seems to put # symbols in front of some of their variable names for it's JSON API. Have a look at a sample response here. As soon as I try and access #text with JavaScript I get an invalid symbol error in the console. Any quick fixes or reasons for this hash?

like image 333
greenimpala Avatar asked Dec 21 '10 13:12

greenimpala


1 Answers

jQuery is only used to retrieve the data. Accessing the #text data is done through straight JavaScript syntax, something like data.recenttracks.track.artist["#text"]

You can't do artist.#text , because # is an invalid first character symbol to be used for accessing an object member. Use the square brackets instead.

like image 186
Luca Matteis Avatar answered Sep 30 '22 13:09

Luca Matteis