Hi, I am trying to set variables from JSON values from the URL I am passing:
https://api.tfl.gov.uk/Line/Route?app_id=6573044a&app_key=7a97df35339dc68625384077a5e07304
here is my code:
func getfromJSON(){
let url = Foundation.URL(string: "https:/
let request = NSMutableURLRequest(url: url! as URL)
let task = URLSession.shared.dataTask(with: request as URLRequest) { data,response,error in guard error == nil && data != nil else {
print("Error:",error)
return
}
let httpStatus = response as? HTTPURLResponse
if httpStatus?.statusCode == 200 {
if data?.count != 0 {
let responseString = try! JSONSerialization.jsonObject(with: data!, options: .allowFragments)
print(responseString)
} else {
}
} else {
print("error httpstatus code is: ", httpStatus!.statusCode)
}
}
task.resume()
}
Please help