JSON - msg.d is undefined error

Posted by Narmatha Balasundaram on Stack Overflow See other posts from Stack Overflow or by Narmatha Balasundaram
Published on 2010-04-21T13:14:51Z Indexed on 2010/04/21 14:03 UTC
Read the original article Hit count: 419

Filed under:

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:

  1. 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?
  2. 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)

© Stack Overflow or respective owner

Related posts about jQuery