python解析json文件
程序员文章站
2024-02-03 09:52:46
...
import json
import xlwt
def loadFont():
f = open("2020110386440427.json", encoding='utf-8')
setting = json.load(f)
family = setting['hits']['hits'] #[0]['_source']['cust_ser_acct_no']
pin_list=[]
shop_supplier_id=[]
shop_supplier_name=[]
order_d7_sale_qtty=[]
est_pass_rate=[]
receive_qtty=[]
new_resp_avg_duration=[]
workbook = xlwt.Workbook(encoding='utf-8')
data_sheet = workbook.add_sheet('demo')
for i in family:
pin = i['_source']['cust_ser_acct_no']
shop_id = i['_source']['shop_supplier_id']
shop_name = i['_source']['shop_supplier_name']
order_d7_qtty = i['_source']['order_d7_sale_qtty']
est_rate = i['_source']['est_pass_rate']
receive = i['_source']['receive_qtty']
new_avg_duration=i['_source']['new_resp_avg_duration']
pin_list.append(pin)
shop_supplier_id.append(shop_id)
shop_supplier_name.append(shop_name)
order_d7_sale_qtty.append(order_d7_qtty)
est_pass_rate.append(est_rate)
receive_qtty.append(receive)
new_resp_avg_duration.append(new_avg_duration)
for i in range(len(pin_list)):
data_sheet.write(i, 0, pin_list[i])
data_sheet.write(i, 1, shop_supplier_id[i])
data_sheet.write(i, 2, shop_supplier_name[i])
data_sheet.write(i, 3, order_d7_sale_qtty[i])
data_sheet.write(i, 4, est_pass_rate[i])
data_sheet.write(i, 5, receive_qtty[i])
data_sheet.write(i, 6, new_resp_avg_duration[i])
workbook.save('demo.xls')
loadFont()
上一篇: asp下返回以千分位显示数字格式化的数值
下一篇: 正则表达式匹配两个字符串,该怎么处理