资讯

展开

python格式化json文件_pycharm对齐线

作者:快盘下载 人气:

大家好,又见面了,我是你们的朋友全栈君。

1.json文件保存

将数据保存为json格式,并存储到.json文件中,需要注意键值对均用双引号,而非单引号。 样例如下所示:

{ 
   "sampleDB": { 
   "shippedVsCustDemand": [{ 
   "CUSTOMER": "customer1", "ITEM": "desk", "SUPPLIEDQTY": 25, "DEMANDQTY": 3}, { 
   "CUSTOMER": "customer1", "ITEM": "drawer", "SUPPLIEDQTY": 15, "DEMANDQTY": 12}, { 
   "CUSTOMER": "customer1", "ITEM": "table", "SUPPLIEDQTY": 52, "DEMANDQTY": 6}, { 
   "CUSTOMER": "customer2", "ITEM": "end table", "SUPPLIEDQTY": null, "DEMANDQTY": 5}, { 
   "CUSTOMER": "customer2", "ITEM": "leg", "SUPPLIEDQTY": null, "DEMANDQTY": 10}, { 
   "CUSTOMER": "customer2", "ITEM": "round table", "SUPPLIEDQTY": null, "DEMANDQTY": 15}, { 
   "CUSTOMER": "customer3", "ITEM": "desk", "SUPPLIEDQTY": null, "DEMANDQTY": 21}, { 
   "CUSTOMER": "customer3", "ITEM": "desk top", "SUPPLIEDQTY": null, "DEMANDQTY": 14}, { 
   "CUSTOMER": "customer3", "ITEM": "end table", "SUPPLIEDQTY": 1, "DEMANDQTY": 7}], "totalManufItems": [{ 
   "ITEM": "desk", "TOTALMANUFQTY": 25}, { 
   "ITEM": "end table", "TOTALMANUFQTY": 155}]}}

2.组合键

在pycharm中,使用组合键ctrl+alt+L进行格式化。 效果如下所示:

{ 
   "sampleDB": { 
   "shippedVsCustDemand": [{ 
   "CUSTOMER": "customer1", "ITEM": "desk", "SUPPLIEDQTY": 25, "DEMANDQTY": 3},
                                      { 
   "CUSTOMER": "customer1", "ITEM": "drawer", "SUPPLIEDQTY": 15, "DEMANDQTY": 12},
                                      { 
   "CUSTOMER": "customer1", "ITEM": "table", "SUPPLIEDQTY": 52, "DEMANDQTY": 6},
                                      { 
   "CUSTOMER": "customer2", "ITEM": "end table", "SUPPLIEDQTY": null,
                                       "DEMANDQTY": 5},
                                      { 
   "CUSTOMER": "customer2", "ITEM": "leg", "SUPPLIEDQTY": null, "DEMANDQTY": 10},
                                      { 
   "CUSTOMER": "customer2", "ITEM": "round table", "SUPPLIEDQTY": null,
                                       "DEMANDQTY": 15},
                                      { 
   "CUSTOMER": "customer3", "ITEM": "desk", "SUPPLIEDQTY": null, "DEMANDQTY": 21},
                                      { 
   "CUSTOMER": "customer3", "ITEM": "desk top", "SUPPLIEDQTY": null,
                                       "DEMANDQTY": 14},
                                      { 
   "CUSTOMER": "customer3", "ITEM": "end table", "SUPPLIEDQTY": 1, "DEMANDQTY": 7}],
              "totalManufItems": [{ 
   "ITEM": "desk", "TOTALMANUFQTY": 25}, { 
   "ITEM": "end table", "TOTALMANUFQTY": 155}]}}

参考: [1] https://www.it610.com/article/1295759947937685504.htm

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/173195.html原文链接:https://javaforall.cn

加载全部内容

相关教程
猜你喜欢
用户评论
快盘暂不提供评论功能!