How get JSON data in AFNetworking, Swift?
Code AFNetworking:
let manager = AFHTTPRequestOperationManager()
manager.responseSerializer = AFHTTPResponseSerializer()
manager.POST("http://api.address",
parameters: nil,
success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in
println("Object: " + responseObject.description)
if let data = responseObject as? Dictionary<String, AnyObject> {
println("JSON: " + "\(data)")
} else {
println("Error JSON")
}
},
failure: { (operation: AFHTTPRequestOperation!,error: NSError!) in
println("Error: " + error.localizedDescription)
})
Result:
Object: < symbols >
Error JSON
I tried it in Alamofire, and it can successfully cast to the Dictionary object.