YouTube API v3在JSON中没有响应Alamofire

问题描述 投票:-1回答:1

我正在使用YouTube API v3在Alamofire的查询中获取搜索结果。这是我的代码:

Alamofire.request(makeURL(query: "https://www.googleapis.com/youtube/v3/search?part=snippet&q=apple&key=AIzaSyAbwfyC36pq1WoaGOkdx7m8cLMh8kMQRGE"), method: .get, parameters: nil).validate().responseJSON { (response) in
    print(response.result.value)     
}

我期待的是:API响应意味着是JSON。

实际发生的事情:它不是JSON而是其他东西。

如何以JSON的形式获得响应?

json swift youtube-api alamofire youtube-data-api
1个回答
0
投票
Alamofire.request("https://www.googleapis.com/youtube/v3/search?part=snippet&q=apple&key=AIzaSyAbwfyC36pq1WoaGOkdx7m8cLMh8kMQRGE").responseJSON { (response) in
            print(response)
        }

结果是JSON格式

SUCCESS: {
    etag = "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/XGmvZBQRhfhL_NmuaAj4nOXRYgE\"";
    items =     (
                {
            etag = "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/3wIsul9XoecWMttT8KgkS-NJVsY\"";
            id =             {
                kind = "youtube#video";
                videoId = hq3yfQnllfQ;
            };
            kind = "youtube#searchResult";
            snippet =             {
                channelId = "UCBnZ16ahKA2DZ_T5W0FPUXg";
                channelTitle = "ChuChu TV Nursery Rhymes & Kids Songs";
                description = "ABC \"Phonics\" song. This animated phonics song will help children learn the sounds of the letters in the English alphabet. This colorful phonics song also ...";
                liveBroadcastContent = none;
                publishedAt = "2014-03-06T20:57:50.000Z";
                thumbnails =                 {
                    default =                     {
                        height = 90;
                        url = "https://i.ytimg.com/vi/hq3yfQnllfQ/default.jpg";
                        width = 120;
                    };
                    high =                     {
                        height = 360;
                        url = "https://i.ytimg.com/vi/hq3yfQnllfQ/hqdefault.jpg";
                        width = 480;
                    };
                    medium =                     {
                        height = 180;
                        url = "https://i.ytimg.com/vi/hq3yfQnllfQ/mqdefault.jpg";
                        width = 320;
                    };
                };
                title = "Phonics Song with TWO Words - A For Apple - ABC Alphabet Songs with Sounds for Children";
            };
        },
                {
            etag = "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/deVTTMRJ83lNlVBvgZ-IAmhGW74\"";
            id =             {
                channelId = "UCE_M8A5yxnLfW0KghEeajjw";
                kind = "youtube#channel";
            };
            kind = "youtube#searchResult";
            snippet =             {
                channelId = "UCE_M8A5yxnLfW0KghEeajjw";
                channelTitle = Apple;
                description = "Apple revolutionized personal technology with the introduction of the Macintosh in 1984. Today, Apple leads the world in innovation with iPhone, iPad, Mac, ...";
                liveBroadcastContent = none;
                publishedAt = "2005-06-22T05:12:23.000Z";
                thumbnails =                 {
                    default =                     {
                        url = "https://yt3.ggpht.com/-KdgJnz1HIdQ/AAAAAAAAAAI/AAAAAAAAAAA/4vVN7slJqj4/s88-c-k-no-mo-rj-c0xffffff/photo.jpg";
                    };
                    high =                     {
                        url = "https://yt3.ggpht.com/-KdgJnz1HIdQ/AAAAAAAAAAI/AAAAAAAAAAA/4vVN7slJqj4/s800-c-k-no-mo-rj-c0xffffff/photo.jpg";
                    };
                    medium =                     {
                        url = "https://yt3.ggpht.com/-KdgJnz1HIdQ/AAAAAAAAAAI/AAAAAAAAAAA/4vVN7slJqj4/s240-c-k-no-mo-rj-c0xffffff/photo.jpg";
                    };
                };
                title = Apple;
            };
        },
                {
            etag = "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/VlSh6Sn6qQgT1FNtsvJ9sUkw8ag\"";
            id =             {
                kind = "youtube#video";
                videoId = hXxsTy74Qsg;
            };
            kind = "youtube#searchResult";
            snippet =             {
                channelId = "UCS83hSDCu-fVLvRLQ1aiktQ";
                channelTitle = "Jolly Toy Art";
                description = "Hi guys~ It's Yuna. Let's draw and color Apple & cutlery set ! Don't forget to Subscribe & Like drawing and coloring Glitter closet for kids and toddlers. Thanks For ...";
                liveBroadcastContent = none;
                publishedAt = "2019-02-01T03:00:02.000Z";
                thumbnails =                 {
                    default =                     {
                        height = 90;
                        url = "https://i.ytimg.com/vi/hXxsTy74Qsg/default.jpg";
                        width = 120;
                    };
                    high =                     {
                        height = 360;
                        url = "https://i.ytimg.com/vi/hXxsTy74Qsg/hqdefault.jpg";
                        width = 480;
                    };
                    medium =                     {
                        height = 180;
                        url = "https://i.ytimg.com/vi/hXxsTy74Qsg/mqdefault.jpg";
                        width = 320;
                    };
                };
                title = "Glitter Apple cutlery set coloring and drawing for Kids, Toddlers | Jolly Toy Art \U2606";
            };
        },
                {
            etag = "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/UnM3fnWWNiSH-CV6p2o8URgd2bI\"";
            id =             {
                kind = "youtube#video";
                videoId = aAUGkuVEbq8;
            };
            kind = "youtube#searchResult";
            snippet =             {
                channelId = UCqSmraORoX9ZE8s7nfEdcuA;
                channelTitle = "Life is Fabulous";
                description = "Apple & Caterpillar Drawing For Kids Thanks for watching!";
                liveBroadcastContent = none;
                publishedAt = "2018-06-08T21:40:21.000Z";
                thumbnails =                 {
                    default =                     {
                        height = 90;
                        url = "https://i.ytimg.com/vi/aAUGkuVEbq8/default.jpg";
                        width = 120;
                    };
                    high =                     {
                        height = 360;
                        url = "https://i.ytimg.com/vi/aAUGkuVEbq8/hqdefault.jpg";
                        width = 480;
                    };
                    medium =                     {
                        height = 180;

                        url = "https://i.ytimg.com/vi/aAUGkuVEbq8/mqdefault.jpg";
                        width = 320;
                    };
                };
                title = "Apple & Caterpillar Drawing For Kids";
            };
        },
                {
            etag = "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/2jayGhnvbSrxvPCW6IM3M1Zlnws\"";
            id =             {
                kind = "youtube#video";
                videoId = Zc7xmtDkLCE;
            };
            kind = "youtube#searchResult";
            snippet =             {
                channelId = "UCj34AOIMl_k1fF7hcBkD_dw";
                channelTitle = EverythingApplePro;
                description = "Why the iPhone 11 lens is so big! iOS 13 passport support, Mini LED future, original Apple phone prototype & more Apple leaks & news. Last Apple leaks.";
                liveBroadcastContent = none;
                publishedAt = "2019-04-15T17:22:34.000Z";
                thumbnails =                 {

                    default =                     {
                        height = 90;
                        url = "https://i.ytimg.com/vi/Zc7xmtDkLCE/default.jpg";
                        width = 120;
                    };
                    high =                     {
                        height = 360;
                        url = "https://i.ytimg.com/vi/Zc7xmtDkLCE/hqdefault.jpg";
                        width = 480;
                    };
                    medium =                     {
                        height = 180;
                        url = "https://i.ytimg.com/vi/Zc7xmtDkLCE/mqdefault.jpg";
                        width = 320;
                    };
                };
                title = "iPhone 11 Lens Explained + Apples Future Tech!";
            };
        }
    );
    kind = "youtube#searchListResponse";
    nextPageToken = CAUQAA;
    pageInfo =     {
        resultsPerPage = 5;
        totalResults = 1000000;
    };
    regionCode = PK;
}
© www.soinside.com 2019 - 2024. All rights reserved.