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);

 

posted @ 2016-08-18 18:13  kakaisgood  阅读(115)  评论(0编辑  收藏  举报