JSON數據的優化

JSON數據的能夠優化嗎?確定能夠,以前都是使用XML,但以後用XML愈來愈少了,就是由於XML包含的冗餘信息太多了。那麼JSON數據有沒有冗餘呢?數據結構

確定有,名稱就是重複的!!less

例如以下的JSON數據:優化

{"total":28,"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,其餘的依次類推,是否是就能夠減小近一半的數據呢?spa

{"total":28,"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相似的文件格式,固然這種改動比較大,能夠說直接改變了數據結構,影響比較大。.net

固然也能夠採用給個字段從新命名的方式修改,例如:code

var attr1={"A":"productid","B":"productname","C":"unitcost","D":"status","E":"listprice","F":"attr1","G":"itemid"}
{"total":28,"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/51810566blog

相關文章
相關標籤/搜索