2014-10-30 189 views
5

我是新来的iOS开发。我试图加载JSON,这里是我的功能:NSURLErrorDomain错误代码1002描述

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() 
      }) 
    }) 

但我收到此错误:

error not nil:::::: 
The operation couldn’t be completed. (NSURLErrorDomain error -1002.) 

我能够通过相同的URL,以获得JSON的浏览器。 我试过阅读THIS: 但我无法获得描述。

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

+0

-1002是NSURLErrorUnsupportedURL,这表明你的'urlPath'是错误的。 – 2014-10-30 07:45:39

+0

NSURLErrorDomain错误-1002表示“NSURLErrorUnsupportedURL”或“kCFURLErrorUnsupportedURL”。这很可能是您的url字符串在url前缀中缺少“http://”。 – 2014-10-30 07:46:01

+0

@AsifAsif:但是你从哪里得到这些错误代码的描述? – sasquatch 2014-10-30 07:53:54

回答

相关问题