我是swift的新手,因为缺乏处理json数据的经验,我无法解决这个问题:
/*response handler*/
var response : NSURLResponse? = nil
var error : NSError? = nil
let responseData = NSURLConnection.sendSynchronousRequest(request, returningResponse:&response, error:&error)
println(responseData)
if (responseData == nil ){
println("error message")
} else {
var encodedResponsedData:NSString = NSString(data:responseData!, encoding:NSUTF8StringEncoding)
println(encodedResponsedData);
let jsonData : NSDictionary = NSJSONSerialization.JSONObjectWithData(responseData!, options:NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary
println(jsonData["error"])
}
在
println(encodedResponsedData);
步骤返回
{“success”:1,“error”:“没有错误消息”,“user_id”: - 1}
然而`
让jsonData:NSDictionary = NSJSONSerialization.JSONObjectWithData(responseData! 选项:NSJSONReadingOptions.MutableContainers,错误:&错误)as NSDictionary
在此步骤中,应用程序崩溃并返回
fatal error: unexpectedly found nil while unwrapping an Optional value
感谢您提供的任何帮助!谢谢!
答案 0 :(得分:0)