使用Alamofire的POST请求时,对象数组设置为参数

时间:2015-10-11 04:37:29

标签: ios alamofire

我正在使用Alamofire向服务器发送请求,请求正文包含一个参数形式:

list: [ { "phone":"13917115283", "name": "Sky" }, { "phone":"13689652145", "name": "RJ" } ]

知道如何发布此类请求吗?感谢

1 个答案:

答案 0 :(得分:2)

您可以使用 SwiftyJSON

轻松实现此目标

通过Cocoapods或手动安装。 对于手动,您只需在工作区中下载并添加SwiftyJSON.xcodeproj文件即可。

在Build Phases中为iOS添加SwiftyJSON框架

enter image description here

现在只需将其导入ViewController

即可
 import SwiftyJSON

即使在导入后如果Xcode没有识别它。清理并构建它。

<强>代码

var arrDic: NSArray = [
      ["phone": "13917115283", "name": "Sky"]
    , ["phone": "13689652145", "name": "RJ"]
                        ]
let response = [ "list" : JSON(arrDic) ]

print(JSON(response))

最终输出

enter image description here

相关问题