代码之家  ›  专栏  ›  技术社区  ›  Moshe

为iOS开发RSS阅读器?

  •  0
  • Moshe  · 技术社区  · 14 年前

    我喜欢制作一个从网站上阅读文章的应用程序,比如RSS或JSON。我使用什么方法将XML或JSON抓取到我的应用程序?如何判断数据何时在本地可用?

    谢谢。

    编辑: 我使用的是用于iOS的Objective-C。我需要iOS代码。

    2 回复  |  直到 12 年前
        1
  •  1
  •   Zafer    14 年前

    我不知道你用的是什么编程语言,但我可以分享我用C语言开发的代码片段。它获取WordPress博客的RSS内容,解析该内容,并显示3个顶级博客文章链接。

    int blogitemcount = 3;
    string wordpressBlog = "wordpress blog address";
    System.Net.WebClient wc = new System.Net.WebClient();
    byte[] buffer = wc.DownloadData("http://" + wordpressBlog + "/feed/rss");
    wc.Dispose();
    wc = null;
    if(buffer.Length > 0) {
        string content = Encoding.UTF8.GetString(buffer);
        XmlDocument xdoc = new XmlDocument();
        xdoc.LoadXml(content);
        XmlNodeList nodes=xdoc.SelectNodes("/rss/channel/item");
        string linkformat = "<a href='{0}' target='_blank' class='blogitem'>{1}</a>";
        for(int i=0; i < nodes.Count && i < blogitemcount;i++ )
        {
            XmlNode n = nodes[i];
            this.ltItems.Text += string.Format(linkformat, n.SelectSingleNode("link").InnerText, n.SelectSingleNode("title").InnerText);
        }
    }
    
        2
  •  1
  •   Moshe    14 年前

    你可能会在这件事上有一些头绪 tutorial from Gigaom