JSON的全名為JavaScript Object Notation,提供便利又易懂方法來儲存資訊,下面就是一個簡單的例子:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var holan = { | |
"age" : "3x", | |
"hometown" : "Yunlin, Taiwan", | |
"gender" : "male" | |
}; |
下面是陣列的例子:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var holanfamily = [{ | |
"name" : "Holan", | |
"age" : "3x", | |
"gender" : "male" | |
}, | |
{ | |
"name" : "Cat", | |
"age" : "3", | |
"gender" : "male" | |
}, | |
{ | |
"name" : "Dog", | |
"age" : "4", | |
"gender" : "female" | |
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.write(holanfamily[2].name); // 輸出 Cat | |
document.write(holanfamily[1].gender); // 輸出 male |
沒有留言:
張貼留言