3

I watched the Jared Davidson's video about parsing JSON with SwiftJSON. I followed this video : https://www.youtube.com/watch?v=_NfijT6mt6A

IT WAS WORKING FINE !! ... but the JSON file was a local file. Now I want to move this file to my website !

This was my code before trying to use a remote JSON file (this code was working very well) :

 let path: String = NSBundle.mainBundle().pathForResource("Database", ofType: "json") as String!
            let jsonData = NSData(contentsOfFile: NSURL(string: path) as NSData!
            let readableJSON = JSON(data: jsonData, options: NSJSONReadingOptions.MutableContainers, error: nil)

            // Récupère et classe les élèment de la date

            let title = readableJSON["dates"][todayDate]["title"].string as String!

To be able to parse the JSON file stored on my website I changed this line : let jsonData = NSData(contentsOfFile: NSURL(string: path) as NSData!

to this :

let jsonData = NSData(contentsOfURL: NSURL(string: "http://mywebsite.com/Database.json")!) as NSData!

AND BOOOMM : Error :( when I run the Simulator

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb) 
zaph
  • 111,848
  • 21
  • 189
  • 228
Omid
  • 178
  • 3
  • 12
  • PS: Go for a better tutorial. The mentioned syntax `as String!` in the video is very bad and not recommended at all for optional binding. – vadian Mar 27 '16 at 15:00
  • The question has nothing to do with JSON, it is about the security of the website. – zaph Mar 27 '16 at 15:05

1 Answers1

2

Google "resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file." and the first item will answer the question completely!

Transport security has blocked a cleartext HTTP

Wondering why it seemed easier to ask a question on SO that just googling the error message.

Community
  • 1
  • 1
zaph
  • 111,848
  • 21
  • 189
  • 228