JSON数据压缩
1
<script src="https://cdn.bootcss.com/lz-string/1.4.4/base64-string.js"></script>
1
2
3
4
5
6
7
8
9
10
11
// sample json object
var jsonobj = {'sample': 'This is supposed to be ling string', 'score': 'another long string which is going to be compressed'}

// compress string before storing in localStorage
localStorage.setItem('mystring', LZString.compress(JSON.stringify(jsonobj)));

// decompress localStorage item stored
var string = LZString.decompress(localStorage.getItem('mystring'))

// parse it to JSON object
JSON.parse(string);

https://stackoverflow.com/questions/20773945/storing-compressed-json-data-in-local-storage

https://stackoverflow.com/questions/294297/javascript-implementation-of-gzip

文章作者: kyren
文章链接: http://huluo666.github.io/2017/12/27/JSON数据压缩/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Kyren's Blog