import requests import pandas as pd from 公用.业务.login import LogIn mytoken = LogIn().take_login() headers = { 'Content-type': 'application/json', 'Accept': 'application/json', 'token': mytoken } url = r"https:####" data = { "alarmTypeLabel": "###", "deviceTypeClass": "0", "createFrom": "2024-01-01 00:00:00", "createTo": "2024-02-01 23:59:59" } response = requests.post(url, json=data, headers=headers) dict_data = response.json().get('data').get('rows')
方式1: # data_list = [] # for ime in dict_data: # dic = {} # dic['公司名称'] = ime.get('device').get('deptName') # dic['imei'] = ime.get('imei') # dic['报警时间'] = ime.get('createTime') # data_list.append(dic) #
方式2:列表推导式 data_list = [ { '公司名称': ime.get('device').get('deptName'), 'imei': ime.get('imei'), '报警时间': ime.get('createTime') } for ime in dict_data ] print(data_list)
使用推导式简化了代码,优化了代码结构
标签:简洁,ime,推导,get,列表,json,imei,dic,data From: https://www.cnblogs.com/xujunhui/p/18001519