Json

<!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() 关系图



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值