NSURLErrorDomain错误代码1002说明

sas*_*tch 8 json ios swift

我是iOS开发的新手.我正在尝试加载JSON,这是我的功能:

func loadmyJSON (urlPath: String) {      

    let url: NSURL = NSURL(string: urlPath)!

    let session = NSURLSession.sharedSession()

    let task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in
               println("Task completed")
        if(error != nil) {
            // If there is an error in the web request, print it to the console
            println("error not nil::::::")
            println(error.localizedDescription)
        }
        var err: NSError?

        var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
        if(err != nil) {
            // If there is an error parsing JSON, print it to the console
            println("JSON Error \(err!.localizedDescription)")
    }


        let results: NSArray = jsonResult["variants"] as NSArray
                    dispatch_async(dispatch_get_main_queue(), {

            self.jsonTable = results
            self.productView!.reloadData()
           })
     })
Run Code Online (Sandbox Code Playgroud)

但是我收到了这个错误:

error not nil::::::
The operation couldn’t be completed. (NSURLErrorDomain error -1002.)
Run Code Online (Sandbox Code Playgroud)

我可以通过相同的URL在浏览器中获取JSON.我试过读这个:但我无法得到描述.

这个错误代码是什么意思?

Asi*_*sif 25

NSURLErrorDomain error -1002NSURLErrorUnsupportedURLkCFURLErrorUnsupportedURL.它表示在大多数情况下,http://URL前缀中缺少URL.

NSURLErrorDomain可以在此处找到所有代码的列表:https://developer.apple.com/documentation/foundation/1508628-url_loading_system_error_codes