我正在迁移到快速2.0,我很好地使用了下面的代码。但我在斯威夫特2中犯了错误。
SRWebClient.POST("upload url")
.data(imageData, fieldName:"image_field", data: ["username":"username","key":"test"])
.send({(response:AnyObject!, status:Int) -> Void in
if status == 200 {
var s_status=response?["status"] as! Int
...对于var s_status行,我将得到以下错误。
Cannot subscript a value of type 'AnyObject!' with an index of type 'String'我怎么才能修好它?
发布于 2015-09-25 22:06:25
错误告诉您,您不能在AnyObject类型的对象上使用“状态”,因为如果它不是字典,它可能无法工作。您需要首先将响应转换为字典。
我看到您使用的是SRWebClient,我从未使用过,但是根据他们的github,这似乎是安全的:
let responseJSON = response! as Dictionary<String, String>我猜他们应该先在代码中序列化。不过我不知道..。在强制转换之前,我要确保该对象是字典。
https://stackoverflow.com/questions/32791232
复制相似问题