I'm just learning json. I'm trying to create an array of object Messages, The declaration does not give me a error, but when I try to access it using the following code serverReply2.Mesages[0].Date, i get an error:

Uncaught TypeError: Cannot read property '0' of undefined

code:

 this.serverReply2 = {"Messages": [
    {"Date": "1/1/1",
      "Mwessage": "test messageA",
      "Attachmentsd": ["link2","link2"]},

 {"Date": "1/1/2",
      "Mwessage": "test messageB",
      "Attachmentsd": ["link2","link2"]},

 {"Date": "1/1/3",
      "Mwessage": "test messageC",
      "Attachmentsd": ["link2","link2"]},     
 ]
 };

 alert( serverReply2.Mesages[0].Date );
share|improve this question
7  
You have written Mesages instead of Messages. – Gazler Jan 16 '12 at 22:19
2  
And serverReply2 instead of this.serverReply2 – vaugham Jan 16 '12 at 22:21

2 Answers

up vote 1 down vote accepted

You have a typo, it should be Messages, not Mesages

alert( serverReply2.Messages[0].Date );
share|improve this answer
Thank you for the insite – Ted pottel Jan 19 '12 at 12:57

Besides the typo, you'd better use console.log() instead of alert().

A JavaScript Console (like in Firebug) will provide error messages like:

TypeError: serverReply2.Mesages is undefined

which might point you toward the typo.

share|improve this answer

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.