我正在使用SwiftyJSON从youtube api中检索数据。我正在编写快速4码。
我想把描述打印出来
以下是我所拥有的:
func getFeedVideos() {
Alamofire.request(API_URL, method: .get, parameters: ["part":"snippet", "playlistId":PLAYLIST_ID,"key":API_KEY], encoding: URLEncoding.default, headers: nil).responseJSON { (response) in
if let value = response.result.value {
let json = JSON(value)
print(json["items"]["snippet"]["description"].stringValue)
}
}
}但没有任何描述被打印出来。
以下是youtube API:
"items" : [
{
"kind": "youtube#playlistItem",
"etag": etag,
"id": string,
"snippet": {
"publishedAt": datetime,
"channelId": string,
"title": string,
"description": string,
"thumbnails": {
(key): {
"url": string,
"width": unsigned integer,
"height": unsigned integer
}
},
"channelTitle": string,
"playlistId": string,
"position": unsigned integer,
"resourceId": {
"kind": string,
"videoId": string,
}
},
}发布于 2018-08-24 22:19:05
如果仔细观察响应的第一行,您会注意到以下内容:
"items" : [
[表示items是一个数组,这意味着您应该尝试
items[0]["snippet"]["description"].stringValue
https://stackoverflow.com/questions/52012296
复制相似问题