檢視 Json 的原始碼
←
Json
跳至導覽
跳至搜尋
由於以下原因,您無權編輯此頁面:
您請求的操作只有這個群組的使用者能使用:
使用者
您可以檢視並複製此頁面的原始碼。
==JSON格式說明== *JavaScript Object Notation *[http://www.jsoneditoronline.org/ 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> ==PHP vs JSON== * json_encode * json_decode <php> $cart = array( "orderID" => 12345, "shopperName" => "John Smith", "shopperEmail" => "johnsmith@example.com", "contents" => array( array( "productID" => 34, "productName" => "SuperWidget", "quantity" => 1 ), array( "productID" => 56, "productName" => "WonderWidget", "quantity" => 3 ) ), "orderCompleted" => true ); echo json_encode( $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} */ </php> <php> $jsonString = ' { "orderID": 12345, "shopperName": "John Smith", "shopperEmail": "johnsmith@example.com", "contents": [ { "productID": 34, "productName": "SuperWidget", "quantity": 1 }, { "productID": 56, "productName": "WonderWidget", "quantity": 3 } ], "orderCompleted": true } '; $cart = json_decode( $jsonString ); echo $cart->shopperEmail . "<br>"; echo $cart->contents[1]->productName . "<br>"; </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 *JSON.stringify <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 }; alert ( JSON.stringify( cart ) ); </script> /* {"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> *JSON.parse <vb> <script type="text/javascript"> var jsonString = ' \ { \ "orderID": 12345, \ "shopperName": "John Smith", \ "shopperEmail": "johnsmith@example.com", \ "contents": [ \ { \ "productID": 34, \ "productName": "SuperWidget", \ "quantity": 1 \ }, \ { \ "productID": 56, \ "productName": "WonderWidget", \ "quantity": 3 \ } \ ], \ "orderCompleted": true \ } \ '; var cart = JSON.parse ( jsonString ); alert ( cart.shopperEmail ); alert ( cart.contents[1].productName ); </script> /* 結果如下 cart.shopperEmail 輸出 johnsmith@example.com cart.contents[1].productName 輸出 WonderWidget */ </vb>
返回到「
Json
」。
導覽選單
個人工具
建立帳號
登入
命名空間
頁面
討論
臺灣正體
視圖
閱讀
檢視原始碼
檢視歷史
更多
搜尋
導覽
首頁
近期變更
隨機頁面
MediaWiki說明
工具
連結至此的頁面
相關變更
特殊頁面
頁面資訊