xml - 为 iOS 开发 RSS 阅读器?

标签 xml json sdk ios download

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

谢谢。

编辑: 我正在为 iOS 使用 Objective-c。我需要 iOS 代码。

最佳答案

我不知道你使用什么编程语言,但我可以分享我用 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);
    }
}

关于xml - 为 iOS 开发 RSS 阅读器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3596907/

相关文章:

java - Xstream XML 到对象 vonversion java.lang.NoClassDefFoundError : Could not initialize class net. sf.cglib.proxy.Enhancer

c# - Newtonsoft.Json 使用 php 7.0 json_encode 数组字符串反序列化问题

javascript - Json 识别为 String

xml - 正则表达式匹配不带标签名称的 XML 起始节点

c# - 指示 XmlWriterSettings 使用自闭合标签

javascript - 使用 mongo 脚本导入 JSON

android - 在 ubuntu 机器上为 nativescript 配置 android sdk 的问题

android - 未找到以下类(class) LoginButton facebook android

windows - 更改windows工具包常用安装路径

python - 如何在 Python 中使用 XSLT 转换 XML 文件?