我正在使用这段代码-:
private static func getJson(_ link: String, completion: @escaping (Json?) -> ()) {
let url = URL(string: "https://twitter.com/BCCI/status/1476041561288822788?s=20")!
URLSession.shared.dataTask(with: url) { data, response, error in
guard let data = data, error == nil else {
return completion(nil)
}
if let json = (try? JSONSerialization.jsonObject(with: data)) as? Json {
completion(json)
} else {
completion(nil)
}
}.resume()
}
Run Code Online (Sandbox Code Playgroud)
我想获取json数据并下载链接