qt qml ajax 獲取 json 天氣資料

2021-07-25 01:23:02 字數 1096 閱讀 1642

依賴ajax.js類庫,以下**很簡單的實現了獲取天氣json資料並展示的任務

【testajax.qml】

1 import qtquick 2.0

2 import "ajax.js"as ajax34

5/**6

測試用ajax 獲取 json 資料

7更複雜的ajax呼叫請檢視 qml/network/ 相關示例8*/

9grid

16 text

1718 text

19 text

2021 text

22 text

2324

component.oncompleted:

32);

3334

/*35

// 中華萬年曆的當天及預告天氣介面(可用)

36ajax.get("",

37function(result, json)

42);

43*/

4445

/*46

// 中國天氣網當天及預告天氣介面(介面掛了)

47ajax.get("",

48function(result, json)

53);

54*/55}

56 }

【ajax.js】

1

//get

2function

get(url, success, failure)39

xhr.send();10}

1112

//post

13function

post(url, arg, success, failure)

1422

xhr.send(arg);23}

2425

2627

//處理返回值

28function

handleresponse(xhr, success, failure)catch

(e));38}

39}40}

41else45}

46 }

json巢狀獲取

目前思路 獲取string string轉化為json json在變為string 假如json為 沒寫全,只是個參考,主要是想記錄一下httpclient一般使用情況,外加json轉變問題 不過現在不怎麼用,一般用okhttp,但我是小白,對於一些服務器官網上用的這個httpclient,本來想用...

獲取json資料

通過非同步獲取json來展示資料 效能提高不少。例項如下 前台 使用者名稱 密碼 非同步頁 將datatable轉化為json格式 public string datatabletojson datatable dt if i dt.rows.count 1 return json.tostring...

JSON 遍歷獲取json物件的值

建乙個html lang en charset utf 8 titletitle 1.定義基本格式 var person 獲取name的值 var name person.name var name person name alert name alert person 2.巢狀格式 var per...