<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<p>First Name: <span id="fname"> </span></p>
<SCRIPT TYPE="text/javascript">
var employees = [
{"firstname":"Bill","LastName":"Gates"},
{"firstname":"George","LastName":"Bush"},
{"firstname":"Thomas","LastName":"Carter"}
];
document.getElementById('fname').innerHTML=employees[0].LastName
</SCRIPT>
</body>
</html>
效果图
Json例题1:JSON.parse();
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<SCRIPT TYPE="text/javascript">
var arr = '{"name":"lisi","age":"24","money":"24K"}';
var arrobject = JSON.parse(arr,null);
alert(arrobject.name);
</SCRIPT>
</body>
</html>
效果图
Json例题2:JSON.parse();
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<SCRIPT TYPE="text/javascript">
var arr = '{"status":"1","data":[{"name":"lisi","age":"24","money":"24K"},{"name":"zhaowu","age":"28","money":"25K"}]}';
var arrobject = JSON.parse(arr,null);
alert("name:" + arrobject.data[1].name + ",stauts:" + arrobject.status);
</SCRIPT>
</body>
</html>
效果图
json:存在json数组和json实体
json实体:{键值对}
json数组:[{},{},{}]
eval:
var json对象=eval('('json数据')');
Json例题3:eval()函数例子
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
var str = "{name:'张三',age:'12',sex:'男'}";
var json = eval('(' + str + ')');
alert(json.name);
</script>
</body>
</html>
效果图:
JSON.parse() eval() 关系图