<!DOCTYPE html><html><head><meta charset="utf-8"><title>菜鸟教程(runoob.com)</title></head><body><h2>从 JSON 字符串中创建对象</h2><p>名: <span id="fname"></span><br> 姓: <span id="lname"></span><br> </p> <script>var txt = '{"employees":[' +'{"firstName":"John","lastName":"Doe" },' +'{"firstName":"Anna","lastName":"Smith" },' +'{"firstName":"Peter","lastName":"Jones" }]}';var obj = eval ("(" + txt + ")");document.getElementById("fname").innerHTML=obj.employees[1].firstName document.getElementById("lname").innerHTML=obj.employees[1].lastName </script></body></html>
添加回答
举报
0/150
提交
取消