Error: Extra parameter in request i used Swift 4. Why i have to pass parameters of type [String: Any]?
Error: Extra parameter in request i used Swift 4. Why i have to pass parameters of type [String: Any]?
Alamofire.request(APPURL.GetAccounts, method: .post,
parameters: transactionData,
encoding: JSONEncoding.default,
headers: nil).responseJSON { responseData in }
我的问题是限制我只能通过 [String:Any] 类型的字典的原因是什么?
完整代码:
class func getAccounts( transactionData: [String:Any]?, withCompletionHandler: @escaping (_ response:AnyObject?)->(Void) ) {
Alamofire.request(APPURL.GetAccounts, method: .post,
parameters: transactionData,
encoding: JSONEncoding.default,
headers: nil).responseJSON { responseData in
if((responseData.result.value) != nil) {
let swiftyJsonVar = JSON(responseData.result.value!)
if let resData = swiftyJsonVar["Accounts"].arrayObject {
let resultData = resData as! [[String:AnyObject]]
withCompletionHandler(resultData as AnyObject)
}else{
withCompletionHandler(nil)
}
}else{
withCompletionHandler(nil)
}
}
}
在JSON 格式中,键必须始终是字符串,值可以是任何类型。这就是 JSON 在 Swift 中的工作方式。
Alamofire.request(APPURL.GetAccounts, method: .post,
parameters: transactionData,
encoding: JSONEncoding.default,
headers: nil).responseJSON { responseData in }
我的问题是限制我只能通过 [String:Any] 类型的字典的原因是什么?
完整代码:
class func getAccounts( transactionData: [String:Any]?, withCompletionHandler: @escaping (_ response:AnyObject?)->(Void) ) {
Alamofire.request(APPURL.GetAccounts, method: .post,
parameters: transactionData,
encoding: JSONEncoding.default,
headers: nil).responseJSON { responseData in
if((responseData.result.value) != nil) {
let swiftyJsonVar = JSON(responseData.result.value!)
if let resData = swiftyJsonVar["Accounts"].arrayObject {
let resultData = resData as! [[String:AnyObject]]
withCompletionHandler(resultData as AnyObject)
}else{
withCompletionHandler(nil)
}
}else{
withCompletionHandler(nil)
}
}
}
在JSON 格式中,键必须始终是字符串,值可以是任何类型。这就是 JSON 在 Swift 中的工作方式。