遍历属性
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JSON 对象</h1>
- <p>如何遍历 JSON 对象中的所有属性。</p>
- <p id="demo"></p>
- <script>
- var myObj, x;
- myObj = {"name":"Bill Gates", "age":62, "car":null};
- for (x in myObj) {
- document.getElementById("demo").innerHTML += x + "<br>";
- }
- </script>
- </body>
- </html>