网上有很多关于JSON的说明,JSON是基于JAVASCRIPT的一种轻量型的数据结构,利用JAVASCRIPT的对象功能可以完成很多的数据交换的功能,copy下面的代码运行下,可以看到JSON的用法
<html>
<form>
<body>
<script>
function FirstName()
{
var User = {"UserID":11, "Name":{"FirstName":"Flers","LastName":"Zhu"}, "Email":"zhuleipro◎hotmail.com"};
alert(User.Name.FirstName);
}
function GetList()
{
var UserList =
[
{"UserID":11, "Name":{"FirstName":"Truly","LastName":"Zhu"}, "Email":"zhuleipro◎hotmail.com"},
{"UserID":12, "Name":{"FirstName":"Jeffrey","LastName":"Richter"}, "Email":"xxx◎xxx.com","address":"GZ"},
{"UserID":13, "Name":{"FirstName":"Scott","LastName":"Gu"}, "Email":"xxx2◎xxx2.com"}
];
alert(UserList[1].address);
}
</script>
<input value=FirstName type=button onclick='FirstName();'>
<input value=GetList type=button onclick='GetList();'>
</body>
</form>
</html>
详细内容可以查看http://www.json.org/
Json用于AJAX交换些数据还是很方面的。
<html>
<form>
<body>
<script>
function FirstName()
{
var User = {"UserID":11, "Name":{"FirstName":"Flers","LastName":"Zhu"}, "Email":"zhuleipro◎hotmail.com"};
alert(User.Name.FirstName);
}
function GetList()
{
var UserList =
[
{"UserID":11, "Name":{"FirstName":"Truly","LastName":"Zhu"}, "Email":"zhuleipro◎hotmail.com"},
{"UserID":12, "Name":{"FirstName":"Jeffrey","LastName":"Richter"}, "Email":"xxx◎xxx.com","address":"GZ"},
{"UserID":13, "Name":{"FirstName":"Scott","LastName":"Gu"}, "Email":"xxx2◎xxx2.com"}
];
alert(UserList[1].address);
}
</script>
<input value=FirstName type=button onclick='FirstName();'>
<input value=GetList type=button onclick='GetList();'>
</body>
</form>
</html>
详细内容可以查看http://www.json.org/
Json用于AJAX交换些数据还是很方面的。