python dict 字典

json  dict  

# -*- coding: utf-8 -*-
import json

class Dict(dict):
def __missing__(self, key):
rv = self[key] = type(self)()
return rv $row_data=Dict() print(json.dumps(row_data,indent=4,ensure_ascii=False))

python excel转json

python  excel  

#!/usr/bin/python
#-*- coding: utf-8 -*-
import json, sys
import xlrd
from datetime import date, datetime
from collections import OrderedDict
import json
import codecs
reload(sys)
sys.setdefaultencoding('utf-8')
wb = xlrd.open_workbook(r'E:\dir\school\2.xlsx')
sheet_list = wb.sheet_names()
filename=1for sheet in sheet_list:
    print sheet
    convert_list = []
    sh = wb.sheet_by_name(sheet)
    title = sh.row_values(0)
    for rownum in range(1, sh.nrows):
        rowvalue = sh.row_values(rownum)
        single = OrderedDict()
        for colnum in range(0, len(rowvalue)):
            single[title[colnum]] = rowvalue[colnum]
        convert_list.append(single)

    j = json.dumps(convert_list,ensure_ascii=False,indent=2)
    f=file('E:\dir\school\json\{}.json'.format(filename), 'w')
    f.write(j)
    f.close()
    filename=filename+1