我正在嘗試引用xcode 8中的這個json(link here)中的所有「標題」。問題是在我可以提取標題數據之前需要引用一個對象和數組(我相信),並且我不知道該怎麼做。如何在xcode 8中的對象內引用數組中的對象?
到目前爲止,這是我已經有了:
func fetchFeed(){
let urlRequest = URLRequest(url: URL(string: "http://itunes.apple.com/us/rss/topalbums/limit=10/json")!)
let task = URLSession.shared.dataTask(with: urlRequest) { (data,response,error) in
if error != nil {
print(error)
return
}
self.artists = [Artist]()
do {
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String : AnyObject]
if let feedFromJson = json["feed"]?["entry"] as? [[String : AnyObject]] {
for feedFromJson in feedsFromJson {
let feed = Feed()
if let entry = feedFromJson["entry"] as? String, let author = feedFromJson["domain"] as? String {
feed.entry = entry
article.headline = title
}
self.articles?.append(article)
}
}
DispatchQueue.main.async {
self.tableview.reloadData()
並感謝您的幫助提前!
你是對的,價值(forKeyPath)是敬虔的。這解決了我的問題。謝謝!! – AceVentura