2014-10-30 13 views
5

Tôi mới phát triển iOS. Tôi cố gắng để tải một JSON, đây là chức năng của tôi:NSURLErrorMã lỗi tên miền 1002 mô tả

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

Nhưng tôi nhận được lỗi này:

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

tôi có thể để có được những JSON trong trình duyệt thông qua cùng một URL. Tôi đã thử đọc THIS: nhưng tôi không thể tải mô tả.

Mã lỗi này có nghĩa là gì?

+0

-1002 là NSURLErrorUnsupportedURL, mà chỉ ra rằng bạn 'urlPath' là sai. –

+0

NSURLErrorDomain error -1002 có nghĩa là 'NSURLErrorUnsupportedURL' hoặc' kCFURLErrorUnsupportedURL'. Rất có thể là chuỗi url của bạn thiếu 'http: //' trong tiền tố url. –

+0

@AsifAsif: Nhưng bạn lấy mô tả về mã lỗi ở đâu? – sasquatch

Trả lời

Các vấn đề liên quan