I'm doing AJAX calls to get data from the last.fm API and decided to use JSON as return data type. So far, so good. The problem is this: I want to get the top tracks using the tag.getTopTags
method from the API and it returns me a JSON that isn't sorted by popularity (even though they say it is).
So how do I sort this JSON by count
property (that indicates popularity) once I have this in a variable in my code?
Here's a sample of the JSON (pardon the lack of formatting, this is from a link they give on their website). It goes like this: toptags has tag which contains an array of tags, which have name, count, etc...
Here's the method from my code that requests the top tracks (via GET with a PHP file that's on my web server - this is working fine):
var getTopTracks = function() {
$.getJSON(
settings.PHP_REQUEST_URL,
{
method: "tag.getTopTags",
api_key: settings.LASTFM_APIKEY,
format: "json",
callback: "?"
},
function(data) {
// treat data here
});
};
I know how to show the data and stuff, I'd just like to sort the data before I show it. Anyone know how to do this in a simple way?