【发布时间】:2017-11-16 00:22:33
【问题描述】:
我是 JSON 世界的新手。我刚开始在 Swift 中使用 JSON。
现在,我有以下功能:
func forShow() {
// Using ACORN API to fetch the course codes
guard let url[enter image description here][1]Online = URL(string: "https://timetable.iit.artsci.utoronto.ca/api/20179/courses?code=CSC") else { return }
let session = URLSession.shared
session.dataTask(with: urlOnline) { (data, response, error) in
if let response = response {
print(response)
}
if let data = data {
print(data)
do {
let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers)
print(json)
} catch {
print(error)
}
}
}.resume()
}
我收到所有课程在其代码字符串中包含“CSC”的回复。我想根据响应形成一个包含所有完整课程代码的数组。我将在此处粘贴一门课程的回复:
所以,我想访问图片中看到的所有课程代码。我希望能够访问的是“CSC104H1-F-20179”。
【问题讨论】: