Hi - 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:
- I don't see __type in the JSON object that is returned. Does that mean that the object sent from the server is not JSON formatted?
- When the __type is not a part of the response, I will not be able to use msg.d? (msg.d is undefined)
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 };
}