"Call can throw, but it is not marked with 'try' and the error is not handled "

"Call can throw, but it is not marked with 'try' and the error is not handled "

我是 Swift 的新手,无法在第

行解决此错误
  .map { JSON(data: [=11=]) }
class func liveInfo() -> Observable<JSON> {
    let request = try! URLRequest(url: someURL, method: .get)
    return session.rx
      .data(request: request)
      .map { JSON(data: [=12=]) }
}

SwiftyJSON 的 JSON(data:) 可以抛出异常所以你必须用 try.

标记它

严格解:

.map { (data) in
    do {
        return try JSON(data: data)
    }
    catch {
        fatalError("unable to convert data to JSON")
    }
}

宽松的解决方案:

.compactMap { try? JSON(data: [=11=]) }