我有一个请求:
let authRequest = NSMutableURLRequest(URL: self.authUrl!)
authRequest.HTTPMethod = "POST"
var params = ["email": "me@email.com", "password": "password"] as Dictionary<String, String>
var err: NSError?
authRequest.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: &err)
authRequest.addValue("application/json", forHTTPHeaderField: "Content-Type")
authRequest.addValue("application/json", forHTTPHeaderField: "Accept")
let authSession = NSURLSession.sharedSession().dataTaskWithRequest(authRequest, completionHandler: {data, response, error -> Void in
println("Response: \(response)")
var strData = NSString(data: data, encoding: NSUTF8StringEncoding)
println("Body: \(strData)")
var err: NSError?
let parsedObject: AnyObject? = NSJSONSerialization.JSONObjectWithData(data,
options: nil,
error:&err)
if let fullObject = parsedObject as? NSDictionary {
println("I am a dictionary")
} else {
println("O GOD WHY")
}
})
authSession.resume()
我担心我无法向您展示整个数据,因为这可以深入了解我的公司身份验证和用户模型。但是,有两件事值得注意:
1)strData打印为Body: 可选的([{
2)JSON结构很复杂,包含多个键,这些键映射到整数,字符串,对象({}
),数组([]
)以及对象内的对象和对象数组。 / p>
响应和数据打印出来并且是有效的JSON,但数据无法转换为字典。没有打印错误消息。我该如何调试呢?关于为什么会发生这种情况的任何想法?