Web service JSON GET Swift
var jsonUrl = "http://muratbayri.com"
let session = URLSession.shared
let encodedUrl = jsonUrl.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
let url = URL(string: encodedUrl)
let task = session.dataTask(with: url! as URL){
(data,response,error) -> Void in
do{
let jsonData = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as AnyObject
let results = jsonData["objectname"] as! Array<Dictionary<String,AnyObject>>
for item in results {
let pti = JsonModel(id:item["id"] as! String)
self.arrayObj.append(pti)
DispatchQueue.main.async {
self.tableview.reloadData()
}
}
} catch {}
}
task.resume()