Just My Life & My Work

Posts tagged ‘非同步’

[SwiftUI] Call RESTful API

在 SwiftUI 中,我們想呼叫 API,回傳 JSON 資料,可以怎麼做呢?

此範例將可以持續點擊 Fetch Joke,來呼叫回傳隨機的某笑話。

提供笑話的 API: https://api.chucknorris.io/jokes/random

// 20220509000756
// https://api.chucknorris.io/jokes/random

{
  "categories": [
    
  ],
  "created_at": "2020-01-05 13:42:29.296379",
  "icon_url": "https://assets.chucknorris.host/img/avatar/chuck-norris.png",
  "id": "wBq7IOiXSwOuZScaevFxwg",
  "updated_at": "2020-01-05 13:42:29.296379",
  "url": "https://api.chucknorris.io/jokes/wBq7IOiXSwOuZScaevFxwg",
  "value": "Chuck Norris didnt dial the wrong number......you just answered the wrong phone"
}
(繼續閱讀…)

標籤雲

%d 位部落客按了讚: