【问题标题】:HTTP POST Json format and set AlamofireHTTP POST Json 格式并设置 Alamofire
【发布时间】:2018-10-19 09:20:28
【问题描述】:
["client_ID": "0", "username": "asdf@gmail.com", "grant_type": "password", "password": "12345", "client_secret": "xxxxxxxxxxxxxxxxxxxxx", "scope": "adfs.user"]

格式转换成这个

{"client_ID": "2", "username": "asdf@gmail.com", "grant_type": "password", "password": "12345", "client_secret": "xxxxxxxxxxxxxxxxxxxxx", "scope": "adfs.user"}

【问题讨论】:

  • 问题是什么?
  • 让 postString: 参数 = [ "grant_type" : GRANT_TYPE ,"client_ID" : CLIENT_ID ,"client_secret" : CLIENT_SECRET,"username" : emailString, "password" : passwordString,"scope" : ROLE]
  • 抱歉,我们没有理解这个问题。你真正想要达到的目标是什么?您是否尝试将Dictionary 转换为 JSON 字符串?
  • Alamofire 可以在发送数据时将 Swift 字典转换为 JSON 字典。你试过了吗?在lib的ReadMe中,有sample、explainations等。

标签: ios json swift alamofire


【解决方案1】:

你可以试试这个:

let params: Parameters = [ "grant_type" : GRANT_TYPE ,"client_ID" : CLIENT_ID ,"client_secret" : CLIENT_SECRET,"username" : emailString, "password" : passwordString,"scope" : ROLE] 
let req = Alamofire.request(url, method: .post, parameters: params, encoding:JSONEncoding.default , headers: nil).validate().responseJSON { (response) in

})

【讨论】:

    猜你喜欢
    • 2016-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    相关资源
    最近更新 更多