json 基础教学
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<script type="text/javascript">

var point = { //json定义一个point物件
"x": 3,
"y": 4,
"get": function () {
alert(this.x + "," + this.y);
}
};
// point.get();

// 网络传输需要将物件Object转化为json字符串,stringify()函数
// 当然也是有丢失的,如get()方法丢失。

var jsonStr = JSON.stringify(point)

// json字符串可以重新转化为json物件,parse()函数 ,
// 其中,parse .v 分开

console.log(jsonStr)//传入var

plainObject = JSON.parse(jsonStr)
console.log(plainObject)
</script>

评论