我正在使用Alamofire,它是Swift中的一个HTTP网络库,并试图用下面的json作为请求中的参数发出一个PUT请求,但是它似乎不喜欢versions字段,因为它里面有另一个字典。没有办法吗?
var reqJson = [
"asdf": "sdfs",
"lsd": "asdf",
"asdf" : "coc",
"qwer": "sdf",
"cvc": "kljb",
"xcv": "qwe",
"versions": [
[
"version": "\(version)",
"component": "\(compName)"
]
]
]
Alamofire.request(.PUT, baseURL + "/cli/applicationProcessRequest/request", parameters: reqJson, encoding: .JSON).authenticate(user: _user, password: _passwd).responseJSON{
(_,_,data,error) in
completionHandler(error)
}
似乎是这样,因为参数应该是[String:Anyobject],但另一个字典不是Anyobject吗?
最佳答案
您的请求中没有足够的信息让编译器推断出正确的类型(而是推断出一个NSDictionary,可能是因为嵌套的dictionary)。只需修改您的声明以帮助您顺利完成任务。
let reqJson: Dictionary<String, AnyObject> = [
"asdf": "sdfs",
"lsd": "asdf",
"asdf" : "coc",
"qwer": "sdf",
"cvc": "kljb",
"xcv": "qwe",
"versions": [
[
"version": "abc",
"component": "xyz"
]
]
]
关于ios - Alamofire参数仅接受[String:Anyobject]?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31733630/