I'm trying to test this piece of code to make sure I'm parsing the JSON correctly but the issue I'm running into is that nothing inside of the URLSession code block is getting executed. When I run the program, all I get is the "test2" print statement on the outside. If anyone could help point me in the right direction that would be greatly appreciated, thank you!
import Foundation
struct BMIInfo: Codable {
let bmi: Double
let more: [String]
let risk: String
}
let url = "http://webstrar99.fulton.asu.edu/page3/Service1.svc/calculateBMI?height=60&weight=156"
let urlObj = URL(string: url)
URLSession.shared.dataTask(with: urlObj!) { (data, response, error) in
let dataAsString = String(data: data!, encoding: .utf8)
let decoder = JSONDecoder()
let jsonresult = try! decoder.decode(BMIInfo.self, from: data!)
let bmi = jsonresult.bmi
let more = jsonresult.more
let risk = jsonresult.risk
print(bmi)
print(dataAsString)
print("test")
}.resume()
print("test2")