Simple way of understandiung JSOn with small exmaple...


/ Published in: JavaScript
Save to your folder(s)

Javascritp object notation


Copy this code and paste it in your HTML
  1. <!--<Simple way understanding JSON, Seems to be a very good concept for using objects in JS Multi dimensional arrays>-->
  2. <!--By Shashikanth-->
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  7. <title>Untitled Document</title>
  8.  
  9. <script type="text/javascript">
  10. var employees = { "accounting" : [ // accounting is an array in employees.
  11. { "firstName" : "John", // First element
  12. "lastName" : "Doe",
  13. "age" : 23 },
  14.  
  15. { "firstName" : "Mary", // Second Element
  16. "lastName" : "Smith",
  17. "age" : 32 }
  18. ], // End "accounting" array.
  19. "sales" : [ // Sales is another array in employees.
  20. { "firstName" : "Sally", // First Element
  21. "lastName" : "Green",
  22. "age" : 27 },
  23.  
  24. { "firstName" : "Jim", // Second Element
  25. "lastName" : "Galley",
  26. "age" : 41 }
  27. ] // End "sales" Array.
  28. } // End Employees
  29.  
  30.  
  31.  
  32. document.writeln(employees.accounting[1].firstName + ' - ' + employees.accounting[0].lastName);
  33.  
  34.  
  35.  
  36.  
  37. </script>
  38. </head>
  39.  
  40. <body>
  41. </body>
  42. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.