遍历属性

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JSON 对象</h1>
  6.  
  7. <p>如何遍历 JSON 对象中的所有属性。</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var myObj, x;
  13. myObj = {"name":"Bill Gates", "age":62, "car":null};
  14. for (x in myObj) {
  15. document.getElementById("demo").innerHTML += x + "<br>";
  16. }
  17. </script>
  18.  
  19. </body>
  20. </html>