我的 Swift 代码有问题,其中包括框架 Alamofire 和 SwiftyJson。
我正在尝试通过此 https://gdata.youtube.com/feeds/api/videos?q=kortsagt&max-re%E2%80%8C%E2%80%8Bsults=5&v=2&alt=jsonc&orderby=published 从 YouTube API 获取一些数据
代码工作正常,直到到达行
if let data = jsonObj.arrayValue as [JSON]?{}
然后就死在那里。
这是我的示例代码:
func loadNewVideo(){
if(loadingStatus == false){
loadingStatus == true
dataVideo.removeAll()
Alamofire.request(.GET, "https://gdata.youtube.com/feeds/api/videos?q=kortsagt&max-re%E2%80%8C%E2%80%8Bsults=5&v=2&alt=jsonc&orderby=published").responseJSON { (request, response, json, error) in
//println(json)
if json != nil {
var jsonObj = JSON(json!)
println(jsonObj)
if let data = jsonObj.arrayValue as [JSON]? {
println(data)
dataVideo = data
self.collectionView?.reloadData()
}
else {
println("loading error")
}
}
}
}
else{
println("Loader JSON")
}
}
此代码有什么问题以及如何修复它?
最佳答案
作为评论效果更好,但我没有声誉。 noon在第一个答案的最后指出“你需要弄清楚如何将项目变成视频数据”。我只是希望补充这一点。 YouTube 会给您一个视频 ID。您可以使用第三方库轻松播放视频,例如 this library ,或this library ,还有其他一些,而且它们相当容易实现。
关于api - Swift 中的 Youtube API 到 AlamoFire,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28976257/