W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JSON 对象</h1> <p>如何访问嵌套的 JSON 对象。</p> <p id="demo"></p> <script> var myObj = { "name":"Bill Gates", "age":62, "cars": { "car1":"Porsche", "car2":"BMW", "car3":"Volvo" } } document.getElementById("demo").innerHTML += myObj.cars.car2 + "<br>"; //or: document.getElementById("demo").innerHTML += myObj.cars["car2"]; </script> </body> </html>