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数据的优化的更多相关文章

  1. 关于JSON数据体积优化的一点小心得

    最近在做的一个项目里传输的json数据比较大,造成了线程间的卡顿,于是想优化一下json数据的体积. 可以看到在json文件里有很多无用的字段,这些字段占据了大量的存储空间. 对数据的结构作一下优化, ...

  2. 32、Flask实战第32天:优化json数据的返回

    接着上节,我们通过jsonify返回json数据非常方便 ... return jsonify({"code": 400, "message": message ...

  3. 将Json数据转换为ADO.NET DataSet对象

    Json数据转换为ADO.NET DataSet其实方法有很多,Newtonsoft.Json也提供了DataSet的Converter用以转换Json数据.但是有些情况下DataSet Conver ...

  4. 移动端基于HTML模板和JSON数据的JavaScript交互

    写本文之前,我正在做一个基于Tab页的订单中心: 每点击一个TAB标签,会请求对应状态的订单列表.之前的项目,我会在js里使用 +  连接符连接多个html内容: var html = ''; htm ...

  5. XML 数据请求与JSON 数据请求

    (1)XML 数据请求 使用 AFNetworking 中的 AFHTTPRequestOperation 和 AFXMLParserResponseSerializer,另外结合第三方框架 XMLD ...

  6. 使用 AFNetworking 进行 XML 和 JSON 数据请求

    (1)XML 数据请求 使用 AFNetworking 中的 AFHTTPRequestOperation 和 AFXMLParserResponseSerializer,另外结合第三方框架 XMLD ...

  7. [HTTP那些事] JSON数据

    随着Android的发展,各路大神的贡献,我们可用的轮子越来越多.比如HTTP请求框架,有自家的Volley,Square的okhttp, async-http-lib, 还有聚合版的xUtils以及 ...

  8. 模拟QQ侧滑控件 实现三种界面切换效果(知识点:回调机制,解析网络json数据,fragment用法等)。

    需要用到的lib包 :解析json  gson包,从网络地址解析json数据成String字符串的异步网络解析工具AsyncHttpClient等 下载地址:点击下载 Xlistview 下拉上拉第三 ...

  9. Android 实现Json数据解析,并进行应用!

    从网站上获取数据然后再客户端进行解析是常见的数据交互.下面是常用的一些接口网址: webservice工厂接口 http://www.36wu.com 快递查询接口http://webservice. ...

随机推荐

  1. Cracking The Coding Interview 2.2

    #include <iostream> #include <string> using namespace std; class linklist { private: cla ...

  2. 玩转 React【第02期】:恋上 React 模板 JSX

    往期回顾 前文中我们讲解了利用 ReactElement 来编写React程序,但是我们也看到这种方式编写 React 特别的麻烦,而且层级结构特别不清晰.今天我们来看一种优雅的编写React的代码的 ...

  3. TensorFlow函数:tf.lin_space

    函数:tf.lin_space 别名: tf.lin_space tf.linspace lin_space( start, stop, num, name=None ) 参见指南:生成常量,序列和随 ...

  4. Vue.js与WdatePicker日历控件冲突问题的解决方案

    问题:同时使用Vue.js与WdatePicker时,双向绑定的日期字段获取不到界面输入的值,而且别的字段的值改变后,日期控件的内容会被清空 原因:WdatePicker不是Vue的插件,不能响应Vu ...

  5. ubantu 常用命令

    1.显示日期与时间的命令:date 2.显示日历的命令:cal 3.简单好用的计算器:bc 4.热键“命令补全或文件补齐”:Tab 5.热键“中断目前程序”:Ctrl+C 6.热键“键盘输入结束(En ...

  6. IDEA如何自动生成testNG的测试报告?

    问:eclipse会在test-output目录下自动生成测试报告,想知道IDEA是只可以在控制台那里点击导出手动生成报告么? 答:编译器选择Edit Configuration,找到测试项,找到Li ...

  7. JAVA_模糊查询_重点是concat关键字

    SELECT * FROM user WHERE username LIKE concat('%',#{username},'%') concat : 类似+ ,拼接sql.sql语句中会将+ 重写. ...

  8. [转]内存分配malloc, new , heapalloc

    malloc,new,VirtualAlloc,HeapAlloc性能(速度)比较 http://www.cppblog.com/woaidongmao/archive/2011/08/12/1531 ...

  9. poj 2175 费用流消圈

    题意抽象出来就是给了一个费用流的残存网络,判断该方案是不是最优方案,如果不是,还要求给出一个更优方案. 在给定残存网络上检查是否存在负环即可判断是否最优. 沿负环增广一轮即可得到更优方案. 考虑到制作 ...

  10. 获取图像的ROI模板区域

    前言 项目需要得到视频帧图像的某一区域作为模板,首先需要确定ROI区域的坐标范围,很简单,直接上代码. % /********************************************* ...