JSON数据的使用实例

实例代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

</body>
<script type="text/javascript">
	var people = {
		"username" : "mary",
		"age":"20",
		"info":{"tel":"1234566","celltelphone":788666},
		"address":[
			{"city":"beijing","code":"1000022"},
			{"city":"shanghai","code":"2210444"}
		]
	};
	window.alert(people.username);//mary
	window.alert(people.info.tel);//1234566
	window.alert(people.address[0].city);//beijing
</script>
</html>

运行结果:

JSON数据的使用实例
JSON数据的使用实例
JSON数据的使用实例

相关推荐