2014-10-30 19 views
5

Jestem nowy w rozwoju iOS. Próbuję załadować JSON, tu jest mój funkcji:Kod błędu NSURLErrorDomain 1002 opis

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

Ale ja dostaję ten błąd:

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

jestem w stanie uzyskać JSON w przeglądarce za pośrednictwem tej samej zawartości. Próbowałem przeczytać THIS: , ale nie mogę uzyskać opisu.

Co oznacza ten kod błędu?

+0

-1002 jest NSURLErrorUnsupportedURL, co oznacza, że ​​'urlPath' jest źle. –

+0

Błąd NSURLErrorDomain -1002 oznacza 'NSURLErrorUnsupportedURL' lub' kCFURLErrorUnsupportedURL'. Najprawdopodobniej w ciągu adresu url nie ma "http: //" w przedrostku adresu URL. –

+0

@AsifAsif: Ale skąd otrzymasz opis tych kodów błędów? – sasquatch

Odpowiedz

Powiązane problemy