Created
May 13, 2018 11:54
-
-
Save MohammadArnauti/975f7063c73541853f7c91a30027e8f2 to your computer and use it in GitHub Desktop.
from json to swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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