iPhone、JSon 和压缩
我正在构建一个 iPhone 应用程序,它将向服务器发送和接收大量数据。我正在使用 JSon 来获取数据。 我想知道是否也可以对接收到的数据使用某种压缩,以尝试加快处理速度。如果是这样,哪种压缩最适合 JSon,在哪里可以找到更多相关信息?
谢谢,
I'm building an iPhone app that's going to be sending and receiving large amounts of data to and from a server. I'm using JSon to get the data.
I was wondering if it's possible to also use some sort of compression on the received data in order to try to speed up the process a little bit. If so, which kind of compression works best with JSon, and where can I find more info on it?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
聚会迟到了,但以防万一有人找。
使用 ASIHTTPRequest,它内置了对 gzip 压缩的支持。
这将节省处理解压的开销。
ASIHTTPRequest 处的 gzip
late for party but just in case anyone looking for.
Use ASIHTTPRequest which has inbuilt supports for the gzip compression.
this will save overhead of handling decompression.
gzip at ASIHTTPRequest
iPhone 支持 ZLib。但我认为最好让服务器支持压缩,因为 NSURLRequest 接受来自服务器响应的 gzip 编码。由于 JSON 是可序列化的,这可能是您的最佳选择。
使用 zlib 您可以从客户端使用压缩。
IPhone supports ZLib. But I think its better idea to have your server supporting compression as the NSURLRequest accepts gzip encoding from server responses. As JSON is serializable, this might be the best option for you.
With zlib you can use compression from the client-side.
JSON 本身并不真正关心您对数据使用哪种压缩方式,因此您可以自由选择最适合数据并提供最佳大小/性能的压缩方案。
然而,JSON 期望所有数据均为 UTF-8 格式,因此您需要对压缩数据进行编码,例如使用 base64 编码。
JSON itself doesn't really care what kind of compression you use on your data so you are free to choose the compression scheme that best fits the data and provides the best size/performance.
However JSON expects all data to be in UTF-8 format so you need to encode the compressed data, e.g. by using base64 encoding.
至少有两种用于 JSON 压缩(CJson 和 HPPack)。
如果客户端设备支持 gzip,则使用 JSON 压缩没有任何好处。当同时使用时:gzip 压缩 & json 压缩,改进可以忽略不计。当 gzip 被禁用或不支持时,使用 JSON 压缩确实有意义。
There are at least two algorithms used for JSON compression (CJson & HPack).
If the client device supports gzip, then there is no benefit of using JSON compression. When using both: gzip compression & json compression, the improvement is negligible. Using JSON compression does make sense, when gzip is disabled or not supported.
我认为如果您太关心数据大小,HPack(也称为 JSONH)压缩算法与 gzip 压缩是一个不错的选择。
我尝试用对象数组压缩简单的 json 数据,我使用了两种压缩方法 -
JSONH+gzip 的结果比仅使用 gzip 的结果压缩了大约 7%。就我而言,这是一个很大的数字,我继续进行混合实施。
I think HPack(also known as JSONH) compression algorithm with gzip compression is a good option if you are too concerned about the data size.
I tried compressing a simple json data with array of objects, I used two methods of compression -
The result of JSONH+gzip was around 7% more compressed than the result of just using gzip. In my case this was a significant number and I went ahead with the mixed implementation.