数据序列化
我正在开发一个基于 Objective-C/cocoa 的应用程序。这个应用程序是客户端<->服务器。目前,通信协议基于一些相当简单的 XML。虽然 XML 可以胜任这项任务,但它在任何方面都不是理想的。将数据序列化为 XML 很痛苦,它不是特别轻量级,并且很难合并非数据信息(例如:“下一步执行此操作”)。
我正在寻找替代方案的建议。
我已经考虑过此处列出的一些格式,但尚未做出任何决定。建议?
I've got an Objective-C/cocoa based application that I'm working on. This app is client<->server. Currently, the communcation protocol is based upon some fairly simple XML. While XML works for this task, it is not ideal in any aspect. It's a pain to serialize data to XML, it's not particularly light-weight, and difficult to incorporate non-data information (such as: 'do this next') in.
I'm looking for suggestions to an alternative.
I've considered some of the ones listed here, but haven't decided on any. Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您正在与 Objective-C 服务器通信,您可以使用 Objective-C 中可用的首选序列化方法来研究编码和解码。
NSKeyedArchiver
和
NSKeyedUnarchiver
基本上,您将从
NSKeyedArchiver
获得一个NSData
,并将其发送(字节/长度)到另一部分,并且将其放回 NSData 并使用 NSKeyedUnarchiver 再次将其解压为对象。If you are talking to a Objective-C server you can look into encoding and decoding with the preferred serialization methods available in Objective-C.
NSKeyedArchiver
andNSKeyedUnarchiver
Basically you will get an
NSData
from theNSKeyedArchiver
that you will send (bytes/length) to the other part and there place it back into anNSData
and useNSKeyedUnarchiver
to unpack it into objects again.我在 iPhone 应用程序中使用 JSON - 我通常更喜欢 XML,但我们需要它非常轻量级,所以我们决定使用 JSON。
如果您使用 XML,那么您应该看一下 XPath(如果您还没有看过)——它将为您提供从 XML 数据结构中提取值的强大功能。
I'm using JSON for an iphone application - I typically would prefer XML, but we needed it very lightweight, so we decided on JSON.
If your working with XML, you should take a look at XPath if you've not already - it will give you tremendous power for extracting values from a XML data structure.
你们有什么样的服务器?如果服务器是基于java的,我建议查看 HessianKit作者:弗雷德里克·奥尔森。编码/解码为普通的 Objective-C 类型并放入 NSArrays 和 NSDictionaries 将使体验更流畅。
What kind of server do you have? If the server is java based I'd recommend looking at HessianKit by Fredrik Olsson. Encode/Decode to ordinary Objective-C types and put in NSArrays and NSDictionaries will make the experience smoother.
(便携式)分布式对象有什么问题?
What's wrong with (Portable) Distributed Objects?