Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct QuizDesc: Decodable {
- let title: String
- let desc: String
- let questions: [Questions]
- }
- struct Questions: Decodable {
- let text: String
- let answer: Int
- let answers: [Answers]
- }
- struct Answers: Decodable {
- let answerOne: String
- let answerTwo: String
- let answerThree: String
- let answerFour: String
- }
- let jsonString = "http://tednewardsandbox.site44.com/questions.json"
- guard let url = URL(string: jsonString)else {return}
- URLSession.shared.dataTask(with: url) { (data, response, err) in
- guard let data = data else{return}
- do {
- let quiz = try JSONDecoder().decode(QuizDesc.self, from: data)
- print(quiz.title)
- } catch let jsonErr {
- print("Error", jsonErr)
- }
- }.resume()
Add Comment
Please, Sign In to add comment