Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 900103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:19:44+00:00 2026-05-15T15:19:44+00:00

I’m attempting to parse a JSON feed using the LastFM API but there are

  • 0

I’m attempting to parse a JSON feed using the LastFM API but there are certain elements returned in the JSON array that are prefixed with a # that I don’t know how to reference.

The feed URL is here and it can be seen visualised here.

My jQuery code so far looks like this:

$.getJSON('http://ws.audioscrobbler.com/2.0/?method=geo.getevents&api_key=ca1599876cde298491941da8577de666&format=json&callback=?', function(data) {

        $.each(data.events.event, function(i, item) {

            html += "<li><a class='fm-event' href='" + item.url + "'><h4>" + item.title + "</h4>";
            html += "<p>at " + item.venue.name + ", " + item.venue.location.city + "<br />";
            html += "on " + item.startDate + "</p>";
            html += "<img src='" + item.venue.image.text + "' />"; // This doesn't work. how do I do this?
            html += "</a></li>";
        });

        $("#last-fm-events").append(html);

    });

I’m basically looping through each item in the feed and dynamically building a list which is then appended to the DOM.

What I can’t figure out is how to get at the URLs for the image items in the feed. There are different ones for different sizes. The JSON for the image elements looks like this:

"image": [
            {
              "#text": "http:\/\/userserve-ak.last.fm\/serve\/34\/2243904.gif",
              "size": "small"
            },
            {
              "#text": "http:\/\/userserve-ak.last.fm\/serve\/64\/2243904.gif",
              "size": "medium"
            },
            {
              "#text": "http:\/\/userserve-ak.last.fm\/serve\/126\/2243904.gif",
              "size": "large"
            },
            {
              "#text": "http:\/\/userserve-ak.last.fm\/serve\/252\/2243904.gif",
              "size": "extralarge"
            },
            {
              "#text": "http:\/\/userserve-ak.last.fm\/serve\/_\/2243904\/A38.gif",
              "size": "mega"
            }
          ]
        }

But I don’t understand why the text element in the array is prefixed with a # and how to get the URL for an image of a particular size. Any help appreciated as I’m a jQuery beginner! Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:19:45+00:00Added an answer on May 15, 2026 at 3:19 pm

    That’s a very strange way for them to format the object (barring requirements I’m not aware of, which is entirely likely).

    Basically, there are two ways to get at the property of an object in JavaScript: Using a literal for the name (e.g., obj.propertyName), as you have, or using a string with brackets notation (e.g., obj["propertyName"]). Sometimes you have to use the string approach, if the literal would be an invalid identifier in JavaScript (and #text would be) or if you’re creating the property name on the fly. So to get item.venue.image.#text (which would be invalid), you’d use item.venue.image["#text"] instead.

    But, what you’ve shown us for image is an array where each element has a #text property, not where the array itself does. If you want to find the URL for a given size, unfortunately you have to search through the array for it:

    function findUrl(image, size) {
        var n, entry;
    
        for (n = 0; n < image.length; ++n) {
            // Get this entry from the array
            entry = image[n];
    
            // Is this the size we want?
            if (entry.size == size) {  // (`size` is a valid identifier, can use a literal)
                // Yes, return this URL
                return entry["#text"]; // (`#text` is not, must use brackets and a string)
            }
        }
        return null; // Or "" or undefined or whatever you want to use for "not found"
    }
    

    Using it where you’re having trouble:

    html += "<img src='" + findUrl(item.venue.image, "medium") + "' />";
    

    …assuming you want the “medium” URL.

    Of course, if the API documentation guarantees that certain sizes will be at certain indexes, you don’t need to go searching, you could just index into the array directly. For instance, in the example you showed us, the “medium” URL entry is at position 1 in the array. If that’s guaranteed, you don’t have to search:

    html += "<img src='" + item.venue.image[1]["#text"] + "' />";
    

    …which says “give me the ‘#text’ property of the object at index 1 in the array.” (Well, essentially. In fact, JavaScript arrays aren’t really arrays, but let’s not go into it here…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 439k
  • Answers 439k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this: var links_html_list = []; var links = document.getElementsByTagName('a');… May 15, 2026 at 4:54 pm
  • Editorial Team
    Editorial Team added an answer At last I have found the solution :), here is… May 15, 2026 at 4:54 pm
  • Editorial Team
    Editorial Team added an answer config/environment.rb isn't really the best place, since you can run… May 15, 2026 at 4:54 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.