我正在尝试使用swiftyjson,但出现错误:
可以抛出呼叫,但是标记为“ try”,并且未处理错误。
我已验证我的源JSON很好。我一直在搜索,找不到解决此问题的方法
import Foundation class lenderDetails { func loadLender() { let lenders = "" let url = URL(string: lenders)! let session = URLSession.shared.dataTask(with: url) { (data, response, error) in guard let data = data else { print ("data was nil?") return } let json = JSON(data: data) print(json) } session.resume() } }
谢谢您的帮助!
您应该将其包装成一个do-catch块。在您的情况下:
do-catch
do { let session = URLSession.shared.dataTask(with: url) { (data, response, error) in guard let data = data else { print ("data was nil?") return } let json = JSON(data: data) print(json) } } catch let error as NSError { // error }