我正在尝试用objective-c开发一个应用程序,它将像这样使用XMLReader (https://github.com/amarcadet/XMLReader)解析xml文档:
<episodes>
<title>title title title</title>
<link>link link link</link>
<description>description description description</description>
<item>
<title>title title title</title>
<link>link link link</link>
<description>description description description</description>
</item>
<item>
...
</episodes>老实说,我不知道我该怎么做。我已经导入了zip中包含的两个文件,但是当我尝试调用
NSData *data = http://link.to.xml/file // some data that can be received from remote service
NSError *error = nil;
NSDictionary *dict = [XMLReader dictionaryForXMLData:data
options:XMLReaderOptionsProcessNamespaces
error:&error];它崩溃了,在主线程上给了我一个SIGABRT。有人能帮上忙吗?另外,如何将生成的NSArray或NSDictionary放入表视图中?
发布于 2013-08-22 01:41:28
查看由Troy http://troybrant.net/blog/2010/09/simple-xml-to-nsdictionary-converter/撰写的帖子
此外,还有许多示例可以帮助您入门。请在这里查看类似问题的答案:在实际实现之前,通过一些教程进行编码始终是Xml parsing in iOS tutorial的好主意。
发布于 2013-08-22 01:48:31
你不能只写:
NSData *data = http://link.to.xml/file // some data that can be received from remote service若要从URL获取数据,请执行以下操作。至少使用像NSData的+dataWithContentsOfURL:这样的东西,除了它将是同步的,并且不是非常用户友好。
我认为此时您的问题不是数据解析;除了解析XML之外,获取数据本身就是一个完整的主题。您可以从URL Loading System Programming Guide开始,它将向您展示如何正确获取数据。
https://stackoverflow.com/questions/18364137
复制相似问题