json文件转换成excel

1、环境

python2.7

2、库

xlwt、demjson、json

3、code

# -*- coding: utf-8 -*-
import xlwt,demjson,json
if __name__ == '__main__':
    '''读取excel'''
    x = 0 #初始值 横轴
    y = 0 #初始值 数轴
    wbk = xlwt.Workbook()
    sheet = wbk.add_sheet('sheet 1')

    with open('api.json', 'r') as t:
        data = t.read().decode('utf-8')
        apilist = data.strip(',').split('+')
        for v in apilist:
            string = v.replace("'", '"')
            dictDat = demjson.decode(string.encode('utf-8'))
            # print dictDat[u'methodsName']

            sheet.write(x,y,u'内容')
            sheet.write(x,y+1,dictDat[u'desc'])

            sheet.write(x+1,y,u'URL')
            sheet.write(x+1,y+1,dictDat[u'path'])

            ## 参数
            sheet.write(x+2,y,  u'参数')
            sheet.write(x+2,y+1,u'默认值')
            sheet.write(x+2,y+2,u'类型')
            sheet.write(x+2,y+3,u'说明')

            ## 开始添加参数
            dict1 = dictDat[u'params']
            vv = 1
            for k,v in dict1.items():
                sheet.write(x+2+vv, y,  k)
                v = ( u'' if v == '' else v)
                ss = ( u'字符串' if v == u'' else u'数值')
                sheet.write(x+2+vv, y+1,  v)
                sheet.write(x+2+vv, y+2,  ss)
                sheet.write(x+2+vv, y+3,  '')
                vv += 1
            x = x + 4 + len(dict1)
            wbk.save('api.xlsx')

 

 

转载于:https://www.cnblogs.com/shuangzikun/p/taotao_python_json_excel.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值