-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson.html
More file actions
39 lines (34 loc) · 987 Bytes
/
json.html
File metadata and controls
39 lines (34 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>the study of json</title>
<script>
var a = 12;
var b = 5;
var c = "abc";
//json对象的生成,其需要‘{}’
var json = { a: 12, b: 6, c: "abc" };
//操作json对象中的数据
json.a++;
//调用json对象中的数据
alert(json.a);
alert('这是加中括号的调用方式:' + json['b']);
//json没有length
var arr = [12, 5, 6];
//循环数组
for (var i = 0; i < arr.length; i++) {
alert(i);
}
for (var i in arr) {
alert('第' + i + '个东西:' + arr[i]);
}
//循环json,json的下标是字符串
for (var i in json) {
alert('第' + i + '个东西:' + json[i]);
}
</script>
</head>
<body></body>
</html>