<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
script
</head>
<body>
<p>
Name:<span id="jname"></span><br/>
Age:<span id="jage"></span><br/>
Address:<span id="jAddress"></span><br/>
phone:<span id="jphone"></span><br/>
</p>
<script type="text/javascript" >
var txt='{"employment":['+
'{"name":"dqd"},{"age":21}'+']}';
var obj = eval("("+txt+")");
alert(obj.employment[0].name);
document.getElementById("jname").innerHTML=obj.employment[1].age;
</script>
</body>
</html>
使用eval函数把 JSON 文本转换为 JavaScript 对象
最新推荐文章于 2019-09-03 18:07:14 发布