I am attempting to try to get all 31 teams from the NHL from this JSON link. Here is a look at what the file looks like:
{
"sports":[
{
"name":"hockey",
"slug":"hockey",
"id":70,
"uid":"s:70",
"leagues":[
{
"name":"National Hockey League",
"slug":"nhl",
"abbreviation":"nhl",
"id":90,
"uid":"s:70~l:90",
"groupId":9,
"shortName":"NHL",
"teams":[
{
...team info....
}......
I currently have this do statement in function trying to loop thru all 31 entries in the "teams" array:
if let parsedData = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary {
if let entries: NSArray = parsedData["sports"] as! NSArray {
for entry in entries {
//work with data
}
}
}
I know I have to dig a bit deeper on the "if let entries" line, but I can't seem to get the data I want. Thanks in advance.
parsedData["sports"]is an array, not a dictionary.NSDictionaryandNSArraywith Swift.