API YouTube v3 не отвечает в JSON с помощью Alamofire - PullRequest
0 голосов
/ 16 апреля 2019

Я использую 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?

1 Ответ

0 голосов
/ 16 апреля 2019
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;
}
...