JSON
{
"姓名":"大憨",
"年龄":24
}
-
{
"学生": [
{"姓名":"小明","年龄":23},
{"姓名":"大憨","年龄":24}
]
}
-
名: <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>
-
var obj=JSON.parse(txt);