Skip to content

Instantly share code, notes, and snippets.

@MohammadArnauti
Created May 13, 2018 11:54
Show Gist options
  • Save MohammadArnauti/975f7063c73541853f7c91a30027e8f2 to your computer and use it in GitHub Desktop.
Save MohammadArnauti/975f7063c73541853f7c91a30027e8f2 to your computer and use it in GitHub Desktop.
from json to swift
let url = URL(string: "http://dookanti.com/api/api.php?type=api&action=getCategories&store_id=2" )
let task = URLSession.shared.dataTask(with: url!) { (data, response, error) in
if error != nil {
print ("Error")
} else {
if let myData = data {
do {
let myJson = try JSONSerialization.jsonObject(with: myData, options: []) as AnyObject
if let dictionary = myJson as AnyObject? {
if let dataObject = dictionary["dataObject"] as? [String] {
if let id = dataObject["id"] as AnyObject? {
print (id)
}
}
}
} catch {
// catch error
}
}
}
}
task.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment