-2

I have a remote JSON file that is structured as so:

pano100 {"name":"pano100","thumb":"\/pioneer_farm_100\/thumbnail.jpg"},
pano101 {"name":"pano100","thumb":"\/pioneer_farm_101\/thumbnail.jpg"}

Where the panoXXX corresponds to the class name of the object. I am trying to lookup against the remote JSON and retrieve the thumb value for the specific class for the object I'm on. I've been working with the code below

    var cN = $(this).attr("class");
    $.getJSON( "custom/parse.php", function( data ) {
        alert(data.cN.thumb);
    });

I'm getting the error: undefined is not an object (evaluating 'data.cN.thumb'), how do I instruct Javascript to treat the cN value as the global variable instead of the literal text?

Thank you, -Matt

1 Answers1

3

Use bracket notation:

alert(data[cN].thumb);
tymeJV
  • 103,943
  • 14
  • 161
  • 157