jaminben jaminben - 7 months ago 15
Javascript Question

Get single value from Json response


Possible Duplicate:

I have a nested data structure / JSON, how can I access a specific value?




My Json response looks like this:

[{"referenceid":"999","firstname":"Firstname","middlename":"Middlename","lastname":"Surname","shortlisted":"0"}]


How can I just retrieve the referenceid value? I've searched and searched... tried all sorts of things but I can only return a "undefined".

Thanks

edit:

Forgot my other code:-

function populateFormData() {

var mxKey = $.now();

$.get("\\web\\php\\somesite\\phpData.php?mxKey" + mxKey, function(applicationData) {

console.log("Application Data: " + applicationData);

var jsonData = JSON.parse(applicationData);

console.log("Json Parse Data: " + jsonData);

});


}

Answer

like this:

var a = [{
  "referenceid": "999",
  "firstname": "Firstname",
  "middlename": "Middlename",
  "lastname": "Surname",
  "shortlisted": "0"
}];

alert(a[0].referenceid);