Как лучше всего просматривать информацию API с iOS - PullRequest
1 голос
/ 21 февраля 2012

Есть ли более простой способ обхода массивов / словарей без создания большого количества отдельных NSArrays / NSDictionaries? Я знаю, что вы можете просматривать вложенные словари с точечной нотацией и значением в keypath, но как насчет использования массивов?

Например:

В настоящий момент, если я хочу получить объект по адресу feed.entry.link [4] .href в приведенном ниже результате API, я должен определить массив в keypath "feed.entry", а затем назначить его первую запись в качестве словаря, затем определите массив в keypath «link» и получите доступ к его четвертой записи в качестве словаря, а затем получите доступ к его значению в «href».

Это нормально?

received {
encoding = "UTF-8";
feed =     {
    entry =         (
                    {
            author =                 (
                                    {
                    name =                         {
                        "$t" = swdestiny;
                    };
                    uri =                         {
                        "$t" = "https://gdata.youtube.com/feeds/api/users/swdestiny";
                    };
                }
            );
            category =                 (
                                    {
                    scheme = "http://schemas.google.com/g/2005#kind";
                    term = "http://gdata.youtube.com/schemas/2007#video";
                },
                                    {
                    label = Entertainment;
                    scheme = "http://gdata.youtube.com/schemas/2007/categories.cat";
                    term = Entertainment;
                },
                                    {
                    scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
                    term = Star;
                },
                                    {
                    scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
                    term = Wars;
                },
                                    {
                    scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
                    term = Episode;
                },
                                    {
                    scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
                    term = 3;
                },
                                    {
                    scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
                    term = Revenge;
                },
                                    {
                    scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
                    term = of;
                },
                                    {
                    scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
                    term = the;
                },
                                    {
                    scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
                    term = Sith;
                }
            );
            content =                 {
                "$t" = "sw-destiny.net Trailer for Revenge of the Sith";
                type = text;
            };
            "gd$comments" =                 {
                "gd$feedLink" =                     {
                    countHint = 1567;
                    href = "https://gdata.youtube.com/feeds/api/videos/9kdEsZH5ohc/comments";
                    rel = "http://gdata.youtube.com/schemas/2007#comments";
                };
            };
            "gd$rating" =                 {
                average = "4.7729683";
                max = 5;
                min = 1;
                numRaters = 1132;
                rel = "http://schemas.google.com/g/2005#overall";
            };
            id =                 {
                "$t" = "http://gdata.youtube.com/feeds/api/videos/9kdEsZH5ohc";
            };
            link =                 (
                                    {
                    href = "https://www.youtube.com/watch?v=9kdEsZH5ohc&feature=youtube_gdata";
                    rel = alternate;
                    type = "text/html";
                },
                                    {
                    href = "https://gdata.youtube.com/feeds/api/videos/9kdEsZH5ohc/responses";
                    rel = "http://gdata.youtube.com/schemas/2007#video.responses";
                    type = "application/atom+xml";
                },
                                    {
                    href = "https://gdata.youtube.com/feeds/api/videos/9kdEsZH5ohc/related";
                    rel = "http://gdata.youtube.com/schemas/2007#video.related";
                    type = "application/atom+xml";
                },
                                    {
                    href = "https://m.youtube.com/details?v=9kdEsZH5ohc";
                    rel = "http://gdata.youtube.com/schemas/2007#mobile";
                    type = "text/html";
                },
                                    {
                    href = "https://gdata.youtube.com/feeds/api/videos/9kdEsZH5ohc";
                    rel = self;
                    type = "application/atom+xml";
                }
            );
            "media$group" =                 {
                "media$category" =                     (
                                            {
                        "$t" = Entertainment;
                        label = Entertainment;
                        scheme = "http://gdata.youtube.com/schemas/2007/categories.cat";
                    }
                );
                "media$content" =                     (
                                            {
                        duration = 151;
                        expression = full;
                        isDefault = true;
                        medium = video;
                        type = "application/x-shockwave-flash";
                        url = "https://www.youtube.com/v/9kdEsZH5ohc?version=3&f=videos&app=youtube_gdata";
                        "yt$format" = 5;
                    },
                                            {
                        duration = 151;
                        expression = full;
                        medium = video;
                        type = "video/3gpp";
                        url = "rtsp://v2.cache4.c.youtube.com/CiILENy73wIaGQkXovmRsURH9hMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
                        "yt$format" = 1;
                    },
                                            {
                        duration = 151;
                        expression = full;
                        medium = video;
                        type = "video/3gpp";
                        url = "rtsp://v2.cache5.c.youtube.com/CiILENy73wIaGQkXovmRsURH9hMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
                        "yt$format" = 6;
                    }
                );
                "media$description" =                     {
                    "$t" = "sw-destiny.net Trailer for Revenge of the Sith";
                    type = plain;
                };
                "media$keywords" =                     {
                    "$t" = "Star, Wars, Episode, 3, Revenge, of, the, Sith";
                };
                "media$player" =                     (
                                            {
                        url = "https://www.youtube.com/watch?v=9kdEsZH5ohc&feature=youtube_gdata_player";
                    }
                );
                "media$thumbnail" =                     (
                                            {
                        height = 360;
                        time = "00:01:15.500";
                        url = "http://i.ytimg.com/vi/9kdEsZH5ohc/0.jpg";
                        width = 480;
                    },
                                            {
                        height = 90;
                        time = "00:00:37.750";
                        url = "http://i.ytimg.com/vi/9kdEsZH5ohc/1.jpg";
                        width = 120;
                    },
                                            {
                        height = 90;
                        time = "00:01:15.500";
                        url = "http://i.ytimg.com/vi/9kdEsZH5ohc/2.jpg";
                        width = 120;
                    },
                                            {
                        height = 90;
                        time = "00:01:53.250";
                        url = "http://i.ytimg.com/vi/9kdEsZH5ohc/3.jpg";
                        width = 120;
                    }
                );
                "media$title" =                     {
                    "$t" = "Star Wars Episode 3 Revenge of the Sith Trailer";
                    type = plain;
                };
                "yt$duration" =                     {
                    seconds = 151;
                };
            };
            published =                 {
                "$t" = "2007-05-23T03:31:54.000Z";
            };
            title =                 {
                "$t" = "Star Wars Episode 3 Revenge of the Sith Trailer";
                type = text;
            };
            updated =                 {
                "$t" = "2012-02-20T17:14:37.000Z";
            };
            "yt$statistics" =                 {
                favoriteCount = 763;
                viewCount = 796719;
            };
        }
    );
    xmlns = "http://www.w3.org/2005/Atom";
    "xmlns$gd" = "http://schemas.google.com/g/2005";
    "xmlns$media" = "http://search.yahoo.com/mrss/";
    "xmlns$yt" = "http://gdata.youtube.com/schemas/2007";
};
version = "1.0";

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...