Skip to content

Instantly share code, notes, and snippets.

@shaktiprakash099
Created October 4, 2018 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaktiprakash099/da8d279a57e1e5a029e0d46e799b3094 to your computer and use it in GitHub Desktop.
Save shaktiprakash099/da8d279a57e1e5a029e0d46e799b3094 to your computer and use it in GitHub Desktop.
import Foundation
import UIKit
let json = """
{
"firstname": "shakti",
"lastname": "prakash",
"age":25
}
"""
let jsonData = Data(json.utf8)
struct User:Codable {
var firstname:String
var lastname:String
var age:Int
}
let decoder = JSONDecoder()
do {
let response = try decoder.decode(User.self, from: jsonData)
print(response)
} catch {
print("Parsing Failed")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment