Webmethod returns an array of objects - something like this
{"d":
[[{"Amount":100,"Name":"StackOverflow"},
{"Amount":200,"Name":"Badges"},
{"Amount":300,"Name":"Questions"}]]}
On the client-side, when the JSON is referenced using msg.d, I get a
msg.d is undefined
error. I am using jQuery JavaScript Library v1.4.2
How do I access the elements in the array of objects?
Adding more findings, code and questions:
Some more: 1. I can access the elements from client side using msg[0][0].Amount - How can I specifically JSON format my return object (from the server)
Code Call to the PageMethods
PageMethods.BuildParticipantAsync($get('<%=hdn_AjaxControls.ClientID %>').value, fOnSuccess, fOnFailure);
function onSuccess(msg)
{
alert(msg.d); //This is undefined
}
Web Method
public static object[] BuildParticipantAsync(string lstSAjaxControls)
{
...//do stuff
return new object[] { ArrayOfObject };
}
Guys, here's what I found. Because, I am returning back a object[] and not a composite object of a class. I will not be able to reference using msg.d[0].Amount (as I thought I would be able to). I will have to use msg[0][0].Amount - In a way, it does seem to make a lot of sense.