讀取網頁字串 (1)

15
讀讀讀讀讀讀 (1)

Upload: solana

Post on 09-Jan-2016

48 views

Category:

Documents


1 download

DESCRIPTION

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

TRANSCRIPT

Page 1: 讀取網頁字串 (1)

讀取網頁字串 (1)

Page 2: 讀取網頁字串 (1)

讀取網頁字串 (2)

Page 3: 讀取網頁字串 (1)

讀取網頁字串 (3)

Page 4: 讀取網頁字串 (1)

讀取網頁字串 (4)

Page 5: 讀取網頁字串 (1)

什麼是 JSON

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

• 和 XML 一樣, JSON 也是基於純文字的資料格式。 JSON 的資料格式非常簡單,您可以用 JSON 傳輸一個簡單的 String , Number , Boolean ,也可以傳輸一個陣列,或者一個複雜的 Object 物件。

Page 6: 讀取網頁字串 (1)

JSON 的優點

• 相容性高• 格式容易瞭解,閱讀及修改方便• 支援許多資料格式

(number,string,booleans,nulls,array,associative array)

• 許多程式都支援函式庫讀取或修改 JSON 資料

Page 7: 讀取網頁字串 (1)

number

string

value

object

false

null

array

true

JSON 的語法

• A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.

Page 8: 讀取網頁字串 (1)

{ : }valuestring

object

,

JSON 的語法

• An object is 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).

Page 9: 讀取網頁字串 (1)

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

object 範例

Page 10: 讀取網頁字串 (1)

[ ]value

array

,

JSON 的語法

• An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).

Page 11: 讀取網頁字串 (1)

["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

[[0, -1, 0],

[1, 0, 0],

[0, 0, 1]

]

array 範例

Page 12: 讀取網頁字串 (1)

JSON 與 XML 對應

JSON

XML

Page 13: 讀取網頁字串 (1)

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

Page 14: 讀取網頁字串 (1)

JSON demo

Page 15: 讀取網頁字串 (1)

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("鍵值名稱 ");}

Java 讀取 JSON