我试图将一些参数发布到服务器,如下所示:
["name":"john" , "age":"25"]
但有key/value
需要一组数组,名为tags
,当我将它添加到字典中时,这样
tagsArray = ["#tag1" , "#tag2" , "#tag3"]
["tags":tagsArray] as [String:Any]
我的应用因此错误而崩溃:
- [Swift._SwiftDeferredNSArray dataUsingEncoding:]:无法识别的选择器发送到实例0x600000234080
***由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [Swift._SwiftDeferredNSArray dataUsingEncoding:]:发送到实例的无法识别的选择器 0x600000234080'
我应该如何在字典值中添加数组?
编辑:
let parameters = ["hash":appDefaults.getUserHash() , "string": vHash , "media_title":vTitle , "description":vDescription , "Keywords[]":insertTagArray] as [String : Any]
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(imgData, withName: "photofileupload",fileName: "file.jpg", mimeType: "image/jpg")
for (key, value) in parameters {
multipartFormData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key)
}
},
to:URLserver)
/// rest of code
答案 0 :(得分:0)
当你遍历字典时,它会崩溃,因为你试图编码数组而不是数组中的字符串。您还应该循环遍历字符串数组并对其进行编码。您可以尝试这样做:
.Location Where:=xlLocationAsNewSheet, Name:="Graph"