【发布时间】:2017-03-17 00:57:11
【问题描述】:
我在Swift 中有一个代码,我通过Alamofire 调用我的后端代码:
Alamofire.request(url, method: .post, parameters: (parameters), encoding: JSONEncoding.default)
.validate()
.responseJSON { response in
switch response.result {
case .success:
do {
if let jsonData = try JSONSerialization.jsonObject(with: response.result.value, options:.allowFragments) as? [String:Any] {
for requestJSON in jsonData["geojson"]["features"] {
if let request = SingleCluster.fromJSON(JSON(requestJSON)){
let pinOne = CustomCluster()
pinOne.coordinate = CLLocationCoordinate2D(latitude: request.latitude, longitude: request.longitude)
pinOne.amount = request.amount
self.eventsArray.append(pinOne);
}
}
}
} catch let err{
print(err.localizedDescription)
}
completionHandler!()
case .failure(let error):
print("error")
}
}
问题在于这一行:
if let jsonData = try JSONSerialization.jsonObject(with: response.result.value, options:.allowFragments) as? [String:Any] {
带来一个错误:
Ambiguous reference to member 'jsonObject(with:options:)'
我尝试将其转换为 [String:Any] 或 [String:AnyObject] 但它没有改变任何东西。我在这里做错了什么?
【问题讨论】:
-
也许下面的 SO 线程有帮助? stackoverflow.com/questions/40558133/…
-
@Fahim 是的,我已经看到了,但是由于答案中缺少代码 sn-p 我不知道如何使用这个答案:(
标签: json swift swift3 alamofire swifty-json