0

I did my research and found a working example, but I could not find any documentation that explicitly explains importing JSON from URL and decoding it. Perhaps, I am searching with wrong keywords.

So, what keywords should use to find out how to import JSON from URL in Swift 4? Are there any well-documented blog post or documentations for it?

I went to the Apple's official documentation on JSON decoding and it says...

import Foundation

let data: Data // received from a network request, for example
let json = try? JSONSerialization.jsonObject(with: data, options: [])

This is not helpful at all! I realized a lot of tutorials skip this step to fetch JSON from URL or just locally create a JSON object. like this this this

Please help me find a good source for this.

Leonard
  • 2,978
  • 6
  • 21
  • 42
  • how to import JSON from URL in Swift 4 , why not Codable ? – Mohmmad S Oct 23 '18 at 03:20
  • There's nothing specific about loading JSON from a URL. It's just data. There are countless examples of using URLSession. – rmaddy Oct 23 '18 at 03:21
  • While the duplicate is title "in Swift 3", it's still the same thing since your question is about getting the JSON, not parsing it. Of course in Swift 4 you generally using Decodable and not JSONSerialization but there are countless examples of that too. – rmaddy Oct 23 '18 at 03:24
  • @rmaddy Okay ill take a look at the duplicate answer. And also I guess you mean I need to look up `URLSession`? – Leonard Oct 23 '18 at 03:31

0 Answers0