如何最好地通过iOS遍历API信息

时间:2012-02-21 14:51:30

标签: objective-c ios api

在没有创建大量单独的NSArrays / NSDictionaries的情况下,是否有更简单的遍历数组/字典的方法?我知道你可以在keypath上用点表示法和值来遍历嵌套字典,但是当涉及数组时呢?

例如:

目前,如果我想在下面的API结果中找到feed.entry.link [4] .href中的对象,我必须在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";

}

0 个答案:

没有答案