【发布时间】:2018-03-16 11:54:39
【问题描述】:
我正在创建一个项目,当单击按钮时,我必须在 UI 文本视图中显示 YouTube 搜索 API 响应。现在我在控制台中得到响应。 1) 如何将其显示为 JSON 响应。 2) 如何在 UI 文本视图中显示。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var resultTextView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func goButton(_ sender: Any) {
guard let url = URL(string: "https://www.youtube.com/watch?v=6Zf79Ns8_oY")else {
return
}
let session = URLSession.shared
let task = session.dataTask(with: url) {(data, response, error) in
if let response = response {
print(response)
}
if let jsondata = data {
print(jsondata)
}
}
task.resume()
}
}
【问题讨论】:
-
请添加您的回复文本
标签: ios json swift api youtube