I'm having trouble accessing/printing some nested JSON data. The code below works when I use commented print(json) to print the entire array, but when I try to step inside the the objects it gives an error. I think it's because instead of a straight array the structure is a little different. JSON data is nested in a dictionary called "data"
Would love some help trying to print the "title" fields as an example. Thanks a lot.
func fetchTvItems() {
let url = NSURL(string: "hidden")
URLSession.shared.dataTask(with: url! as URL) { (data, response, error) in
if error != nil {
print(error ?? "URLSession error")
return
}
do {
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers)
for dictionary in json as! [[String: AnyObject]] {
print(dictionary["title"]!)
}
//print(json)
} catch let jsonError {
print(jsonError)
}
}.resume()