D
D
Dauren S2016-12-05 09:26:34
JSON
Dauren S, 2016-12-05 09:26:34

Swift3 doesn't parse from http, only https?

Why doesn't Swift 3 want to parse json from http. 2 identical files and parsing only with https

func fetchArticles(){
       let urlRequest = URLRequest(url: URL(string: "https://api.myjson.com/bins/my4j")!)
        
        let task = URLSession.shared.dataTask(with: urlRequest) { (data,response,error) in
            
            if error != nil {
                print(error)
                return
            }
            
            self.articles = [Article]()
            do {
                let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String : AnyObject]
                
                if let articlesFromJson = json["results"] as?  {
                    for articleFromJson in articlesFromJson {
                        let article = Article()
                        if let title = articleFromJson["title"] as? String {
                    
                            //article.author = author
                            //article.desc = desc
                            article.headline = title
                            //article.url = url
                            //article.imageUrl = urlToImage
                        }
                        self.articles?.append(article)
                    }
                }
                DispatchQueue.main.async {
                    self.tableview.reloadData()
                }
                
            } catch let error {
                print(error)
            }
            
            
        }
        
        task.resume()
        
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Donkovtsev, 2016-12-05
@dauren101

App Transport Security

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question