加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

错误:请求中的额外参数我使用Swift 4.为什么我必须传递[String

发布时间:2020-12-14 04:55:09 所属栏目:百科 来源:网络整理
导读:Alamofire.request(APPURL.GetAccounts,method: .post,parameters: transactionData,encoding: JSONEncoding.default,headers: nil).responseJSON { responseData in } 我的问题是限制我只能传递类型字典[String:Any]的原因是什么? 完整代码: class func
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,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中的工作方式.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读