I am trying to parse an json from a webserver i am using and i can't actually manage to do that although i could back in iOS 8. This is the code i am using:
let str = "URL-THAT-HAS-THE-JSON"
let url = NSURL(string: str)
let data = NSData(contentsOfURL: url!)
var names : [String] = []
do
{
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: [] )
if let blogs = json["blogs"] as? [[String: AnyObject]]
{
for blog in blogs
{
if let name = blog["name"] as? String
{
names.append(name)
}
}
}
}
catch {
print("error serializing JSON: \(error)")
}
print (names)
unfortunately i can't give you the url with the json but i can make sure it works on server side.Could someone give me some help on what i am doing wrong?