I am new to iOS development. I am trying to load JSON , here is my function:
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() }) })
But I get this error:
error not nil:::::: The operation couldn't be completed. (NSURLErrorDomain error -1002.)
I can get JSON in the browser through the same URL. I tried reading THIS : but I cannot get a description.
What does this error code mean?
source share