以下是 RxAlamofire 提供的用于发出requestJSON请求的方法,没有方法可以传递参数[String:String]
RxAlamofire.requestJSON(.get, url)
.subscribe(onNext: { [weak self] (r, json) in
if let jsonResult = JSON(json) as? JSON {
if let foodMenuResult = MenuResult(jsonResult) as? MenuResult {
self?.delegate?.showMenu(menuResult: foodMenuResult)
}
}
}, onError: { [weak self] (error) in
self?.delegate?.onError()
},onCompleted: {})
.disposed(by: disposeBag)
如何将参数传递给 RxAlamofire requestJSON方法
答案 0 :(得分:1)
您需要从URL
构建URLComponents
。
var components = URLComponents(string: "https://www.example.com/path")!
components.queryItems = [
.init(name: "param1", value: "value1"),
.init(name: "param2", value: "value2"),
]
let url = components.url!
上面的url
将
https://www.example.com/path?param1=value1¶m2=value2
上面!
的使用应该没有问题,因为您传递的数据应该是有效的。尽管请评估这些方法的文档,以评估正确处理nil
的要求。