Je suis nouveau sur le développement iOS . J'essaye de charger un JSON , voici ma fonction:
func loadmyJSON (urlPath: Ssortingng) { let url: NSURL = NSURL(ssortingng: 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() }) })
Mais je reçois cette erreur:
error not nil:::::: The operation couldn't be completed. (NSURLErrorDomain error -1002.)
Je suis en mesure d'get le JSON dans le browser via la même URL. J'ai essayé de lire ceci : mais je ne peux pas get la description.
Que signifie ce code d'erreur?
NSURLErrorDomain error -1002
signifie NSURLErrorUnsupportedURL
ou kCFURLErrorUnsupportedURL
. Il indique qu'une mauvaise URL a été fournie, dans la plupart des cas, http://
absent du préfixe d'URL.
La list de tous les codes NSURLErrorDomain
peut être trouvée ici: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/index.html#//apple_ref/doc/constant_group/URL_Loading_System_Error_Codes