ios - 如何在帖子正文中使用 RxAlamofire 传递 json 进行帖子调用
问题描述
我想使用RxAlamofire进行 post 调用,它提供了函数 requestJson,它需要两个参数 类型 get 或 post 和 url但是没有参数来传递 post json body如何做到以下是我的代码
var components = URLComponents(string: url)!
components.setQueryItems(with: param)
let url = components.url!
print("\(url)")
RxAlamofire.requestJSON(.post, url)
.subscribe(onNext: { [weak self] (r, json) in
if let jsonResult = JSON(json) as? JSON {
if let cartResult = FoodCartResult(jsonResult) as? FoodCartResult {
self?.delegate?.showCart(cartresult: cartResult)
}
}
}, onError: { [weak self] (error) in
print(error.localizedDescription)
self?.delegate?.onError()
},onCompleted: {})
.disposed(by: disposeBag)
解决方案
其实其他参数都包含在requestJson的定义中,只是有默认参数而已。所以你可以放心地说:
RxAlamofire.requestJSON(.post,
url,
parameters: ["param1": "value1"],
encoding: JSONEncoding.default,
headers: nil)
推荐阅读
- paypal - 用于 PayPal 沙盒的正确 URL 和参数是什么?
- java - SpEL 函数更改字符串
- python - 从 python 脚本运行时无法执行脚本文件 (.bat)
- angular - 插件导入的离子黑屏
- php - Visual Composer vc_map() 动态下拉列表和依赖项
- python - 对于嵌套的二维数组,我怎样才能得到最后一列的数组?在列上拆分?
- excel - Excel VBA - 为每个日期添加额外天数的日期循环,直到相邻列结束
- javascript - 如何将节点数组对象展开为表示目录结构的嵌套对象
- html - 如何使用:悬停动画另一个元素来定位一个元素
- powershell - 尝试使用 Powershell 从全局地址列表中删除所有未经许可的用户