使用 plist 的网络服务
我一直在使用 NSXMLParser 来解析 xml 并成功启动应用程序...最近我遇到了 xml 的问题...因为 xml 很重。它增加了内存开销...我计划转向 plist (因为它大大减少了内存开销)。并且不知道从哪里开始...我已经在整个网络中进行了搜索,但没有成功,你们能给我一个示例代码,甚至是包含 plist 的工作网址吗...已经足够了...我如果你们能帮助我,我将非常感激。
I've been using NSXMLParser
for parsing xml and was successful in launching apps ... Recently I'm facing problems with xml ... Since xml is heavy weight. It increases the memory over head ... I'm planning to shift to plist(since it reduces the memory overhead considerably). And have no idea where to begin with ... I've searched all through the net and was not successful could u guys gimme me a sample code or even a working url containing a plist ... Is more than enough ... I'd be so grateful if u guys could help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您可以控制数据的格式,您是否考虑过使用 JSON 来代替?
if you have control over the format of the data, have you considered using JSON instead?
您可以使用 https://github.com/jayway/CWFoundationCWXMLTranslator > 轻松从 XML 转换为域对象。
假设您有这个域类:
和这个 XML:
您只需定义一个翻译文件,将其命名为
Book.xmltranslation
,并添加以下内容:然后,它将用于从该文件中获取和转换 XML服务器到
Book
类的实时实例中,如下所示:这是最简单的用例,如果需要,甚至可以内联编写翻译 DSL。 CWXMLTranslator 还支持更复杂的操作,例如日期、URL、数字等的类型转换,以及嵌套类型,以及直接转换为 Core Data 托管对象。
CWFoundation 项目包含您需要的所有文档以及解析 RSS 源的示例项目。
You can use the
CWXMLTranslator
from https://github.com/jayway/CWFoundation for easy translation from XML to domain object.Assume you have this domain class:
And this XML:
You only need to define a translation file, name it
Book.xmltranslation
, and add this:That would then be used to fetch and trabnslate the XML fromt he server into live instances of your
Book
class like this:This is the easiest usecase available, the translation DSL can even be written inline if you want. The
CWXMLTranslator
support much more complex operations also, like type convertions to dates, URLs, numbers, etc. As well as nested types, and direct translation to Core Data managed objects.The CWFoundation project contains all documentation you need, and a sample project that parses RSS feeds.
现代 plist是 XML:属性列表。可以使用和创建二进制 plist,但它们只是二进制 XML 的一种形式。这反过来意味着开销会有所减少,但会牺牲可读性。 JSON 可以小于等效的 XML,但并非总是如此。
抛开所有这些不谈,plist 往往比同等的 XML 更冗长。将 XML:
与等效的 plist 进行比较:
Modern plists are XML: Property Lists. It's possible to use and create binary plists, but they're just a form of binary XML. That can in turn mean some reduction in overhead, but at the cost of readability. JSON can be smaller than equivalent XML, though not always.
Leaving all that aside, plists tend to be more verbose than equivalent XML. Compare the XML:
with an equivalent plist: