I'm trying to parse out some data thats returned from a web service via json with the following code.
function getADData() {
var strSearch = $('#txtSearch').val()
var ajaxData = "{ 'PartNameString': '" + strSearch + "' }";
$.ajax({
type: "POST",
url: "/Services/ActiveDirectoryInterop.asmx/SearchUsers",
data: ajaxData,
contentType: "application/json; charset=utf-8",
dataType: "json",
success:populateTable
});
}
function populateTable(result) {
alert(result["d"].length);
}
Data Returned is this.
{"d":{"Columns":["UserID","Name","Email"],"Rows":[["U99999","Lees, Smith","[email protected]"],["U99999","Lees, Mark","[email protected]"],["99999","Lees, Bob","[email protected]"],["U999999","Lees, John","[email protected]"],["U999999","Lees, Jim","[email protected]"]]}}
What the alert though jsut returns undefined. So i know I'm missing something and it probably has to do with the nesting of the JSON. Can someone point me in the right direciton for some materials or code that shows me how to possibly traverse data like what i'm recieving.
Try this instead:
alert(result.d.Columns.length);
And read up on that weirdo 'd'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With