1 / 15

讀取網頁字串 (1)

讀取網頁字串 (1). 讀取網頁字串 (2). 讀取網頁字串 (3). 讀取網頁字串 (4). 什麼是 JSON. JSON ( JavaScript Object Notation )是一種羽量級的資料交換格式,易於閱讀和編寫,同時也易於機器解析和生成,非常適合於伺服器與用戶端的交互。 JSON 採用與程式設計語言無關的文本格式,但是也使用了類 C 語言的習慣,這些特性使 JSON 成為理想的資料交換格式。

solana
Download Presentation

讀取網頁字串 (1)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 讀取網頁字串(1)

  2. 讀取網頁字串(2)

  3. 讀取網頁字串(3)

  4. 讀取網頁字串(4)

  5. 什麼是JSON • JSON(JavaScript Object Notation)是一種羽量級的資料交換格式,易於閱讀和編寫,同時也易於機器解析和生成,非常適合於伺服器與用戶端的交互。JSON採用與程式設計語言無關的文本格式,但是也使用了類C語言的習慣,這些特性使JSON成為理想的資料交換格式。 • 和 XML 一樣,JSON 也是基於純文字的資料格式。JSON的資料格式非常簡單,您可以用 JSON 傳輸一個簡單的 String,Number,Boolean,也可以傳輸一個陣列,或者一個複雜的Object 物件。

  6. JSON 的優點 • 相容性高 • 格式容易瞭解,閱讀及修改方便 • 支援許多資料格式 (number,string,booleans,nulls,array,associative array) • 許多程式都支援函式庫讀取或修改 JSON 資料

  7. JSON 的語法 • Avaluecan be astringin double quotes, or anumber, ortrueorfalseornull, or anobjector anarray. These structures can be nested.

  8. JSON 的語法 • Anobjectis an unordered set of name/value pairs. An object begins with{(left brace)and ends with}(right brace). Each name is followed by:(colon)and the name/value pairs are separated by,(comma).

  9. object範例 { "name": "Jack B. Nimble", "at large": true, "grade": "A", "format": { "type": "rect", "width": 1920, "height": 1080, "interlace": false, "framerate": 24 } }

  10. JSON 的語法 • Anarrayis an ordered collection of values. An array begins with[(left bracket)and ends with](right bracket). Values are separated by,(comma).

  11. array範例 ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] [ • [0, -1, 0], • [1, 0, 0], • [0, 0, 1] ]

  12. JSON與XML對應 JSON XML

  13. 一個簡單的 JSON 範例 JSON字串:

  14. JSON demo

  15. Java讀取JSON JSONArray items = new JSONArray(body); for (int i = 0;i<items.length();i++){ JSONObject json_data = items.getJSONObject(i); String data1 = json_data.getString("鍵值名稱"); int data2 = json_data.getInt("鍵值名稱"); double data3 = json_data.getDouble("鍵值名稱");}

More Related