JSON學習總結

來源:互聯網
上載者:User

標籤:blog   http   java   使用   os   檔案   資料   html   

花括弧儲存對象方括弧儲存數組數組[];對象 {}數組對象:[ {},{},{}  ](1)、複雜JSON對象。{"employees": [{ "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName":"Jones" }],"student":{  "name":"John Johnson",  "street":"Oslo West 16",   "age":33,  "phone":"555 1234567"}}C# 代碼;class Employees_Object{  Empemployees[] employees;  Student student;  }(2)、單個對象var JSONObject = {  "name":"John Johnson",  "street":"Oslo West 16",   "age":33,  "phone":"555 1234567"};      C# 代碼;  Class JSONObject  {     public string name{get;set;} public string street{get;set;} public string age{get;set;} public string phone{get;set;}  }   (3)、數組對象var employees = [{ "firstName" : "John" , "lastName" : "Doe" }, { "firstName" : "Anna" , "lastName" : "Smith" }, { "firstName" : "Peter" , "lastName" : "Jones" },  //特別注意此處的逗號;在json線上驗證器中會出錯。 ];  Empemployees[] employees=new Empemployees[]   //List<Empemployees> employees=new List<Empemployees>();{new Empemployee{firstName="John",lastName="Doe"},new Empemployee{firstName="John",lastName="Doe"},new Empemployee{firstName="John",lastName="Doe"},};把 JSON 文本轉換為 JavaScript 對象JSON 最常見的用法之一,是從 網頁伺服器上讀取 JSON 資料(作為檔案或作為 HttpRequest),將 JSON 資料轉換為 JavaScript 對象,然後在網頁中使用該資料。http://www.w3cschool.cc/json/json-eval.html由於 JSON 文法是 JavaScript 文法的子集,JavaScript 函數 eval() 可用於將 JSON 文本轉換為 JavaScript 對象。eval() 函數使用的是 JavaScript 編譯器,可解析 JSON 文本,然後產生 JavaScript 對象。必須把文本包圍在括弧中,這樣才能避免語法錯誤:var obj = eval ("(" + txt + ")");

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.