我该如何将音频文件从我的服务器下载到用户的手机上,在应用程序中使用?当我访问网站链接时,会出现像这样的JSON代码。
[{"name":"Lets Party","path":"http:\/\/domain.us\/\/\/audios\/\/Lets Party.wav"},
{"name":"Let You Know","path":"http:\/\/domain.us\/\/\/audios\/\/Let You Know.wav"},
{"name":"OMG","path":"http:\/\/domain.us\/\/\/audios\/\/OMG.wav"}]
我曾尝试在Swift中获取JSON并进行转换,但导致我的应用程序崩溃。但当我使用博客JSON时,它可以完美地工作,没有崩溃。我应该如何在Swift或Objective-C中解决这个问题?
编辑:现在我收到一个错误消息。
当前代码:
let urlPath = "http://www.domain.us/"
let url = NSURL(string: urlPath)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in
if error != nil {
println(error)
} else {
let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
println(jsonResult)
}
})
task.resume()
}
错误信息:
2014-11-12 20:07:23.652 JSON Practice[6073:284290] CFNetwork SSLHandshake failed (-9847)
2014-11-12 20:07:23.874 JSON Practice[6073:284290] CFNetwork SSLHandshake failed (-9847)
2014-11-12 20:07:24.054 JSON Practice[6073:284290] CFNetwork SSLHandshake failed (-9847)
2014-11-12 20:07:24.055 JSON Practice[6073:284290] NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9847)
Error Domain=NSURLErrorDomain Code=-1200 "The operation couldn’t be completed. (NSURLErrorDomain error -1200.)" UserInfo=0x7fc0ba656020 {NSErrorFailingURLStringKey=https://www.domain.us/, NSErrorFailingURLKey=https://www.makemeip.us/, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9847, NSUnderlyingError=0x7fc0ba52ebb0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1200.)"}