Reputation: 4047
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,
Upvotes: 6
Views: 2067
Reputation: 1323
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.
Upvotes: 0
Reputation: 4133
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.
Upvotes: 0
Reputation: 5123
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
Upvotes: 2
Reputation: 9212
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.
Upvotes: 0
Reputation: 2377
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.
Upvotes: 0