「Json」:修訂間差異
跳至導覽
跳至搜尋
| 第17行: | 第17行: | ||
</PHP> | </PHP> | ||
==JQUERY VS JSON== | ==JQUERY VS JSON== | ||
<vb> | |||
{ | |||
"orderID": 12345, | |||
"shopperName": "John Smith", | |||
"shopperEmail": "johnsmith@example.com", | |||
"contents": [ | |||
{ | |||
"productID": 34, | |||
"productName": "SuperWidget", | |||
"quantity": 1 | |||
}, | |||
{ | |||
"productID": 56, | |||
"productName": "WonderWidget", | |||
"quantity": 3 | |||
} | |||
], | |||
"orderCompleted": true | |||
} | |||
</vb> | |||
<vb> | |||
<script type="text/javascript"> | |||
var cart = { | |||
"orderID": 12345, | |||
"shopperName": "John Smith", | |||
"shopperEmail": "johnsmith@example.com", | |||
"contents": [ | |||
{ | |||
"productID": 34, | |||
"productName": "SuperWidget", | |||
"quantity": 1 | |||
}, | |||
{ | |||
"productID": 56, | |||
"productName": "WonderWidget", | |||
"quantity": 3 | |||
} | |||
], | |||
"orderCompleted": true | |||
}; | |||
</script> | |||
</vb> | |||
*getJSON | *getJSON | ||
*parseJSON | *parseJSON | ||
於 2016年12月29日 (四) 14:21 的修訂
JSON格式說明
- JavaScript Object Notation
- JSON格式化的網站
- 物件(object)用大括號 { }
- key-value的方式儲存
- ex {"subject":"Math","score":80}
- json object的鍵值(key),一定要用文字做鍵值
- 陣列(array)用中括號 [ ]
- ex [0,4,5,2,7,8,3]
<PHP> [{"name":"Tom","lastname":"Chen",
"report":[{"subject":"Math","score":80},
{"subject":"English","score":90}]},
{"name":"Amy","lastname":"Lin",
"report":[{"subject":"Math","score":86},
{"subject":"English","score":88}]}]
</PHP>
JQUERY VS JSON
<vb> {
"orderID": 12345,
"shopperName": "John Smith",
"shopperEmail": "johnsmith@example.com",
"contents": [
{
"productID": 34,
"productName": "SuperWidget",
"quantity": 1
},
{
"productID": 56,
"productName": "WonderWidget",
"quantity": 3
}
],
"orderCompleted": true
} </vb> <vb> <script type="text/javascript"> var cart = {
"orderID": 12345,
"shopperName": "John Smith",
"shopperEmail": "johnsmith@example.com",
"contents": [
{
"productID": 34,
"productName": "SuperWidget",
"quantity": 1
},
{
"productID": 56,
"productName": "WonderWidget",
"quantity": 3
}
],
"orderCompleted": true
}; </script> </vb>
- getJSON
- parseJSON