Created
October 4, 2018 06:56
-
-
Save shaktiprakash099/da8d279a57e1e5a029e0d46e799b3094 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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