NSURLErrorDomain错误代码1002说明

编程入门 行业动态 更新时间:2024-10-19 11:50:56
本文介绍了NSURLErrorDomain错误代码1002说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是 iOS 开发的新手。我正在尝试加载 JSON ,这是我的函数:

I am new to iOS development. I am trying to load a JSON, here's 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() }) })

但我收到此错误:

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

我能够通过相同的URL在浏览器中获取JSON。 我试过阅读这个:但是我无法获得描述。

I am able to get the JSON in browser through the same URL. I have tried reading THIS: but I can't get the description.

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

What does this error code mean?

推荐答案

NSURLErrorDomain错误-1002 表示 NSURLErrorUnsupportedURL 或 kCFURLErrorUnsupportedURL 。它表示在大多数情况下提供了错误的URL,从URL前缀中缺少 http:// 。

NSURLErrorDomain error -1002 means NSURLErrorUnsupportedURL or kCFURLErrorUnsupportedURL. It indicates that a bad URL was provided, in most cases, missing from the URL prefix.

可在此处找到所有 NSURLErrorDomain 代码的列表: developer.apple/documentation/foundation/1508628-url_loading_system_error_codes

The list of all NSURLErrorDomain codes can be found here: developer.apple/documentation/foundation/1508628-url_loading_system_error_codes

更多推荐

NSURLErrorDomain错误代码1002说明

本文发布于:2023-11-26 18:16:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634654.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误代码   NSURLErrorDomain

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!