【发布时间】:2017-10-13 12:56:22
【问题描述】:
我想取回频道视频的标题和 ID,但我在 JSON 级别阻止。它的效果是,当我尝试制作 MYJSONARRAY ["items"] [0] 时,没有任何显示:/ 谢谢你的帮助:)
let url = URL(string: "https://www.googleapis.com/youtube/v3/search?key=**************Q&channelId=UCFNHx0ppCqm4EgPzEcOc29Q&part=snippet,id&order=date&maxResults=50")
let task = URLSession.shared.dataTask(with: url!) { (data, reponse, error) in
if error != nil {
print("ERROR")
}else{
if let content = data {
do{
let myJsonArray = try JSONSerialization.jsonObject(with: content, options: JSONSerialization.ReadingOptions.mutableContainers) as AnyObject
print(myJsonArray["items"][0]) //NOT WORKING
//let test1 = myJsonArray["items"]
//print(myJsonArray)
print("\n \n --------------------- \n \n")
if let items = myJsonArray["items"] as? NSDictionary{
print(items) // NOT WORKING
}
}catch{
}
}
}
}
task.resume()
api的答案:https://pastebin.com/uWhmmJcm
谢谢你:)
【问题讨论】:
标签: ios json swift youtube-api