ios - 在 Alamofire 中发送 JSONObject

标签 ios json swift alamofire

如何使用 Alamofire 4.2.0 发送这样的 JSON 格式:

这是我的脚本的一部分:

{
 "session":{
     "email": "user1@gmail.com", 
      "password": "secret123"
   }
 }

谢谢!

最佳答案

您可以在 Dictionary 中构造数据并使用 JSONEncoding.default 作为编码来发送您的请求。

let mydata: [String: [String: String]] = [
   "session": [
       "email": "user1@gmail.com",
       "password": "secret123"
   ]
]

Alamofire.request(url, method: .post, parameter: mydata, encoding: JSONEncoding.default, headers: nil)

关于ios - 在 Alamofire 中发送 JSONObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41565831/

相关文章:

swift - 在 osx 中使用 swift 在 NSView 的图形子类中以编程方式创建文本字段

ios - 在 Swift 中获取 UIBarButtonItem 的框架?

ios - Swift 3 For 循环比较和更改

ios - 如何将 ISO 639 语言代码转换为完整的英文名称?

ios - 导出 Ad Hoc 分发时出错

ios - 在UITableView上添加加载页脚

ios - 如何从添加到 View 的工具栏中关闭 IOS ViewController

Java > 计算 JSON 响应中 null 和 0 的出现次数

json - 在 GraphQL 中过滤无模式 json 对象

php - Highcharts 和 Mysql