JSON初入門

來源:互聯網
上載者:User

標籤:jsonjs   js   jquery   

JSON:Javascript Object Notation

             輕量級的資料交換格式

文法規則:(js對象表示文法的子集)

             1、資料在名稱/值對中

             2、資料由逗號分隔

             3、花括弧{}儲存對象

             4、中括弧【】儲存對象

JSON名稱/值

      資料書寫格式:名稱/值

      包括欄位名稱(雙引號“”),中間:隔開

      “firstName”:“John”     易理解,相當於js中  firstName=“John”

 

JSON值

      數字(整數/浮點數)

      字串(雙引號內“”)

      邏輯值(true或false)

      數組(【】)

      對象({})

      null

 

基礎結構(JSOn簡單而言,就是js中的對象和數組,此也是JSON中的兩種結構)

對象{}    {key:value,key:value,……}

             物件導向的語言中,key:對象的屬性,value:對應的屬性值

             取值方法:   對象.key--數字、字串、數組、對象

對象【】    【“avascript”,“C#”,“PHP”】

具體樣本如下:

 <div id="s" style="margin-top:50px;">    Name:<span id="name" ></span><br />    Age:<span id="age"></span><br />    Address:<span id="address"></span><br />    Phone:<span id="phone"></span><br /> </div> <script type="text/javascript">    var people={"programers":                  [{"name":"a","age":"11","address":"上海","phone":"11111111111"},           {"name":"a1","age":"110","address":"上海0","phone":"11111222222"}],        "authors":[{"name":"b","age":"22","address":"廣州","phone":"222222222222"}],        "flowers":[{"name":"c","age":"33","address":"深圳","phone":"3333333333"}]}$(function(){var name=people.programers[1].name;   //通過賦值進行輸出顯示  var age=people.programers[0].age;var address=people.authors.address;$("#name").text(name);$("#age").text(age);$("#address").text(address);$("#phone").text{people.flowers.phone};   //直接調用輸出顯示       }); </script>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.