2017-08-07 28 views
0

當我試圖編譯下面的代碼,我得到一個錯誤:RxAlamofire:歧義參考構件「JSON(_:_:參數:編碼:頭:)」

Ambiguous reference to member 'json(::parameters:encoding:headers:)'

的代碼被複制和從RxAlamofire Github上庫頁

import RxSwift 
import RxAlamofire 

class CurrencyRest { 

     static func getJson() { 

      let stringURL = "https://api.fixer.io/latest" 

      // MARK: NSURLSession simple and fast 
      let session = URLSession.init() 

      _ = session.rx.json(.get, stringURL) 
       .observeOn(MainScheduler.instance) 
       .subscribe { print($0) } 
     } 

} 

回答

0

粘貼到修復錯誤,session.rx.json(url:)是要走的路,這是從RxCocoa,雖然RxAlamofire,你不必使用URLSession RX擴展名,而是使用json(::parameters:encoding:headers:),例如json(.get, stringURL),它返回您可以用作JSON的Observable<Any>