I am hoping a second set of eyes can help me find my error. I am creating a basic JSON object and trying to display the values in the JSON object. Field 1 displays properly, but fields 2 & 3 display as undefined. Can anyone see what my problem is?
Thanks in advance for your time.
Code:<html> <head> <title>String to JSON in JavaScript</title> <script type="text/javascript"> var mockJSON = { "testing" : [ { "field1" : "field1" }, { "field2" : "field2" }, { "field3" : "field3" } ] }; function createJSON() { alert( "field1: " + mockJSON.testing[0].field1 ); alert( "field2: " + mockJSON.testing[0].field2 ); alert( "field3: " + mockJSON.testing[0].field3 ); } </script> </head> <body onLoad=""> <a href="javascript:createJSON();">Build JSON</a> </body> </html>



Reply With Quote



Bookmarks