Sunday, 15 May 2011

Get data from JSON file in JQuery -



Get data from JSON file in JQuery -

i seek print alert verify data. got them :

$(document).ready(function(){ var info = [ { color: "red", value: "#f00" }, { color: "black", value: "#000" } ]; alert(data.red); });

the alert displays "undefined" because it's not simple json, it's object. how can illustration value of color reddish ?

no, it's undefined because you're doing wrong. try

alert(data[0].color); // spits out "red"

you've got array of objects, , you're trying treat array, , using values if keys.

json

No comments:

Post a Comment