JSON数据的优化
JSON数据的可以优化吗?肯定可以,之前都是使用XML,但之后用XML越来越少了,就是因为XML包含的冗余信息太多了。那么JSON数据有没有冗余呢?
肯定有,名称就是重复的!!
例如如下的JSON数据:
{"total":,"rows":[
{"productid":"FI-SW-01","productname":"Koi","unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"},
{"productid":"K9-DL-01","productname":"Dalmation","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
{"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":38.50,"attr1":"Venomless","itemid":"EST-11"},
{"productid":"RP-SN-01","productname":"Rattlesnake","unitcost":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"},
{"productid":"RP-LI-02","productname":"Iguana","unitcost":12.00,"status":"P","listprice":35.50,"attr1":"Green Adult","itemid":"EST-13"},
{"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":158.50,"attr1":"Tailless","itemid":"EST-14"},
{"productid":"FL-DSH-01","productname":"Manx","unitcost":12.00,"status":"P","listprice":83.50,"attr1":"With tail","itemid":"EST-15"},
{"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":23.50,"attr1":"Adult Female","itemid":"EST-16"},
{"productid":"FL-DLH-02","productname":"Persian","unitcost":12.00,"status":"P","listprice":89.50,"attr1":"Adult Male","itemid":"EST-17"},
{"productid":"AV-CB-01","productname":"Amazon Parrot","unitcost":92.00,"status":"P","listprice":63.50,"attr1":"Adult Male","itemid":"EST-18"}
]}
如果我们假定第一列是productid,第二列是productname,其他的依次类推,是不是就可以减少近一半的数据呢?
{"total":,"rows":[
{"FI-SW-01","Koi",10.00,"P",36.50,"Large","EST-1"},
{"K9-DL-01","Dalmation",12.00,"P",18.50,"Spotted Adult Female","EST-10"},
{"RP-SN-01","Rattlesnake",12.00,"P",38.50,"Venomless","EST-11"},
{"RP-SN-01","Rattlesnake",12.00,"P",26.50,"Rattleless","EST-12"},
{"RP-LI-02","Iguana",12.00,"P",35.50,"Green Adult","EST-13"},
{"FL-DSH-01","Manx",12.00,"P",158.50,"Tailless","EST-14"},
{"FL-DSH-01","Manx",12.00,"P",83.50,"With tail","EST-15"},
{"FL-DLH-02","Persian",12.00,"P",23.50,"Adult Female","EST-16"},
{"FL-DLH-02","Persian",12.00,"P",89.50,"Adult Male","EST-17"},
{"AV-CB-01","Amazon Parrot",92.00,"P",63.50,"Adult Male","EST-18"}
]}
其实这就是csv类似的文件格式,当然这种改动比较大,可以说直接改变了数据结构,影响比较大。
当然也可以采用给个字段重新命名的方式修改,例如:
var attr1={"A":"productid","B":"productname","C":"unitcost","D":"status","E":"listprice","F":"attr1","G":"itemid"}
{"total":,"rows":[
{"A":"FI-SW-01","B":"Koi","C":10.00,"D":"P","E":36.50,"F":"Large","G":"EST-1"},
{"A":"K9-DL-01","B":"Dalmation","C":12.00,"D":"P","E":18.50,"F":"Spotted Adult Female","G":"EST-10"},
{"A":"RP-SN-01","B":"Rattlesnake","C":12.00,"D":"P","E":38.50,"F":"Venomless","G":"EST-11"},
{"A":"RP-SN-01","B":"Rattlesnake","C":12.00,"D":"P","E":26.50,"F":"Rattleless","G":"EST-12"},
{"A":"RP-LI-02","B":"Iguana","C":12.00,"D":"P","E":35.50,"F":"Green Adult","G":"EST-13"},
{"A":"FL-DSH-01","B":"Manx","C":12.00,"D":"P","E":158.50,"F":"Tailless","G":"EST-14"},
{"A":"FL-DSH-01","B":"Manx","C":12.00,"D":"P","E":83.50,"F":"With tail","G":"EST-15"},
{"A":"FL-DLH-02","B":"Persian","C":12.00,"D":"P","E":23.50,"F":"Adult Female","G":"EST-16"},
{"A":"FL-DLH-02","B":"Persian","C":12.00,"D":"P","E":89.50,"F":"Adult Male","G":"EST-17"},
{"A":"AV-CB-01","B":"Amazon Parrot","C":92.00,"D":"P","E":63.50,"F":"Adult Male","G":"EST-18"}
]}
出处:https://blog.csdn.net/xuexiaodong009/article/details/51810566
JSON数据的优化的更多相关文章
- 关于JSON数据体积优化的一点小心得
最近在做的一个项目里传输的json数据比较大,造成了线程间的卡顿,于是想优化一下json数据的体积. 可以看到在json文件里有很多无用的字段,这些字段占据了大量的存储空间. 对数据的结构作一下优化, ...
- 32、Flask实战第32天:优化json数据的返回
接着上节,我们通过jsonify返回json数据非常方便 ... return jsonify({"code": 400, "message": message ...
- 将Json数据转换为ADO.NET DataSet对象
Json数据转换为ADO.NET DataSet其实方法有很多,Newtonsoft.Json也提供了DataSet的Converter用以转换Json数据.但是有些情况下DataSet Conver ...
- 移动端基于HTML模板和JSON数据的JavaScript交互
写本文之前,我正在做一个基于Tab页的订单中心: 每点击一个TAB标签,会请求对应状态的订单列表.之前的项目,我会在js里使用 + 连接符连接多个html内容: var html = ''; htm ...
- XML 数据请求与JSON 数据请求
(1)XML 数据请求 使用 AFNetworking 中的 AFHTTPRequestOperation 和 AFXMLParserResponseSerializer,另外结合第三方框架 XMLD ...
- 使用 AFNetworking 进行 XML 和 JSON 数据请求
(1)XML 数据请求 使用 AFNetworking 中的 AFHTTPRequestOperation 和 AFXMLParserResponseSerializer,另外结合第三方框架 XMLD ...
- [HTTP那些事] JSON数据
随着Android的发展,各路大神的贡献,我们可用的轮子越来越多.比如HTTP请求框架,有自家的Volley,Square的okhttp, async-http-lib, 还有聚合版的xUtils以及 ...
- 模拟QQ侧滑控件 实现三种界面切换效果(知识点:回调机制,解析网络json数据,fragment用法等)。
需要用到的lib包 :解析json gson包,从网络地址解析json数据成String字符串的异步网络解析工具AsyncHttpClient等 下载地址:点击下载 Xlistview 下拉上拉第三 ...
- Android 实现Json数据解析,并进行应用!
从网站上获取数据然后再客户端进行解析是常见的数据交互.下面是常用的一些接口网址: webservice工厂接口 http://www.36wu.com 快递查询接口http://webservice. ...
随机推荐
- Cracking The Coding Interview 2.2
#include <iostream> #include <string> using namespace std; class linklist { private: cla ...
- C++基础知识:STL简介
1.标准模板库STL ― STL , 即 : Standard Template Library , 是 C++的一部分― STL是常用数据结构和算法的集合― STL的目标是标准化组件 , 提高开发效 ...
- SharePoint Framework 企业向导(八)
博客地址:http://blog.csdn.net/FoxDave 构建关于SPFx自定义的计划 在SPFx引入的时候,你就需要对它进行规划了.规划要从介绍SPFx解决方案使用的新的技术栈开始.开 ...
- Kubernetes资源监控探索
搭建kubernetes集群,有一个默认的dashboard,但是这个dashboard比较简陋,不能将自定义展示.所以打算使用Grafana+Heapster+Influxdb构建一个一体化监控平台 ...
- synchronized(五)
package com.bjsxt.base.sync005;/** * synchronized的重入 * @author alienware * */public class SyncDubbo2 ...
- MFC 添加背景图片并让控件背景透明
/*添加背景图片*/ BOOL CTOOLDlg::OnEraseBkgnd(CDC* pDC) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CDialog::OnEraseBkg ...
- python基础题型一
一.执行Python脚本的两种方式 #python name.py Python解析器 #chmod +x name.py 二.简述位.字节的关系 1Byte=8bit 三.简述ascii.uni ...
- Python写一个批量生成账号的函数
批量生成账户信息,产生的账户由@sina.com结尾,长度由用户输入,产生多少条也由用户输入,用户名不能重复,用户名必须由大写字母.小写字母和数字组成. def Users(num,len): # n ...
- ubantu查看进程操作
可以使用ps命令.它能显示当前运行中进程的相关信息,包括进程的PID.Linux和UNIX都支持ps命令,显示所有运行中进程的相关信息. ps命令能提供一份当前进程的快照.如果想状态可以自动刷新,可以 ...
- python 创建flask项目方法
Flask是一个基于Python的web框架,它的设计目的是提供Web开发所需的最小功能子集. Flask与别的框架(尤其是采用其他编程语言的框架)的不同之处在于:它没有绑定诸如数据库查询或者表单处理 ...