javascript使用json(实例)
来源:互联网 发布:网络教育考研究生 编辑:程序博客网 时间:2024/06/05 09:36
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="json.js"></script>
<script type="text/javascript">
function test() {
var jsontext = '{"man":{"weight":"75kg", "age":"24"},"ar":["1", "2", "3", "4"]}';
//解析json
var aman = eval("("+jsontext+")");
//取出json中的信息
alert(aman.man.weight);
}
function showJSON() {
var user = {
"username":"andy",
"age":"24",
"info":{"tel":"123456", "cellphone":"98756"},
"address":[
{"city":"beijing", "postcode":"222233"},
{"city":"newwork", "postcode":"444455"},
]
}
user.username = "tom";
alert("username="+user.username);
alert("age="+user.age);
alert("info="+user.info.cellphone);
alert("address第一个地址 =" + user.address[0].city);
alert("address第二个地址 =" + user.address[1].city);
}
function showCar() {
var carr = new Car("Donge", "Coronet R/T", 123, "yellow");
alert(carr.toJSONString());
}
function Car(make, model, year, color) {
this.make = make;
this.model = model;
this.year = year;
this.color = color;
}
function myEval() {
var str = '{ "name": "Violet", "occupation": "character" }';
var obj = eval('(' + str + ')');
alert(obj.toJSONString());
}
function myEval2() {
var str = '{ "name": "Violet2", "occupation": "character2" }';
var obj = str.parseJSON();
alert(obj.toJSONString());
}
function toJsonString() {
var continents = new Array();
continents.push("Europe");
continents.push("Asia");
continents.push("Australia");
continents.push("Antarctica");
continents.push("North America");
continents.push("South America");
continents.push("Africa");
alert("The JSON representation of the continents array is: " +continents.toJSONString());
}
</script>
</head>
<body>
<input type="button" value="测试JSON" onclick="test();"><br />
<input type="button" value="测试JSON2" onclick="showJSON();"><br />
<input type="button" value="showCar" onclick="showCar();"><br />
<input type="button" value="Eval转换" onclick="myEval();"><br />
<input type="button" value="JSON转换" onclick="myEval2();"><br />
<input type="button" value="toJsonString" onclick="toJsonString();"><br />
</body>
</html>
- javascript使用json(实例)
- json-lib使用实例
- Json使用实例
- Newtonsoft.Json 使用实例
- JSON javascript 使用
- JavaScript 中使用JSON
- JavaScript中JSON使用
- javascript中使用JSON
- javascript JSON.stringify 语法实例讲解
- 使用json传输数组实例
- struts2+ajax+json使用实例
- ajax,json,php使用实例
- JSON 在javascript中使用json
- javascript中将json格式字符串转换成json对象实例
- 在javascript 中使用JSON
- 在 JavaScript 中使用 JSON
- JavaScript中JSON的使用
- 在javascript中使用json
- Java自学总结2
- 基于组件的游戏编程
- Java自学总结3
- json的定义与javascript如何使用json之总结
- C# 中堆栈,堆,值类型,引用类型的理解
- javascript使用json(实例)
- 51单片机控制的电子时钟系统
- spring,ibatis集成的时候碰到问题
- B/S开发中报表生成开发的一点经验
- 用GtkTreeView做进度条
- Linux Signal (4): alarm和pause
- CUDA 2.1 Released
- SQL Server中的补零 (第一篇)
- gedit出错的处理