JSON的二进制编码? [英] binary encoding for JSON?

查看:276
本文介绍了JSON的二进制编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Javascript应用程序正在从服务器下载相当多的数据,我在想,除了由服务器完成的正常的gzip之外,我可以用一些二进制格式而不是文本JSON对数据进行编码。

有没有一个标准的方法?

理想情况下,它应该是一个可以使用JSON文本文件并将其转换为通用二进制格式的小工具和一个解码它的小型JavaScript库。



另外,XHR中是否需要特别处理二进制数据?

解决方案

如果gzip压缩不够好,有可能您的二进制格式也不会,特别是如果您不能在合理的时间内通过javascript解码。 p>

请记住,使用gzip时解压缩是由浏览器本机完成的,比javascript中的任何事情都要快一个数量级。



如果你觉得JSON d eserialization太慢了,因为你支持像ie7这样的老式浏览器,它不解码JSON本身,而​​是依赖于 eval 为该作业,考虑从JSON转移到自定义编码基于字符串拆分,反序列化速度要快得多。



为了灵感,尝试阅读这篇文章:



http://code.flickr.com / blog / 2009/03/18 / building-fast-client-side-searching /


My Javascript application is downloading quite a bit of data from the server and I was thinking that in addition to normal gzip that's done by the server, I can encode the data in some binary format rather than textual JSON.
Is there a standard way of doing this?
Ideally it should be some small tool that can take a JSON text file and convert it to a generic binary format and a small Javascript library which decodes it.

Also, is there something special that needs to be done in XHR to pass binary data?

解决方案

If gzip doesn't compress well enough, chances are your binary format won't either, especially if you wan't to be able to decode it via javascript within a reasonable amount of time.

Remember that the unzipping when using gzip is done natively by the browser and is orders of magnitude faster than anything you can do in javascript.

If you feel that the JSON deserialization is too slow, because you are supporting older browsers like ie7 which doesn't decode JSON natively but depends on eval for the job, consider going away from JSON to a custom encoding based on string splitting, which is much much faster to deserialize.

For inspiration try to read this article:

http://code.flickr.com/blog/2009/03/18/building-fast-client-side-searches/

这篇关于JSON的二进制编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆