我正在尝试从API获取JSON数据,我想在终端上打印它,以检查我是否在终端上接收数据,但出现此错误。我目前正在使用Swift 5。
import UIKit
import Alamofire
typealias JSON = [String: Any]
class NetworkingService {
static let shared = NetworkingService()
private init() {}
func getPeople(completion: () -> Void) {
AF.request("https://launchlibrary.net/1.4/launchstatus").responseJSON{ (response) in
if let json = response.result.value as? JSON { // here I am getting error
print(json)
}
}
}
}
答案 0 :(得分:2)
将您的请求完成块替换为:
switch response.result {
case let .success(value):
print(value)
case let .failure(error):
print(error)
}