Python新手,感谢您的帮助/支持。
我已经能够提取salesforce报告(json文件)并解析文件。我遇到的问题是我需要创建一个字典,该字典将占用每一行并创建一个字典,该字典将获取文件中的所有行并将其变为字典,如下所示:
m_account_number:case_number,report_label,report_id
我认为我可以使用当前的“for循环”执行此操作,因为您可以看到我将它放在循环的底部 blist [ “m_account_number”] [ “CASE_NUMBER”] [ “report_label”] [ “REPORT_ID”]
有人可以帮忙吗?
提前致谢!
import csv
blist = {"m_account_number" :{"case_number", "report_label","report_id"}}
csv_file = open('eggs.csv', 'w', newline='')
csv_writer = csv.writer(csv_file)
facts = parser.data["factMap"]["T!T"]["rows"]
for row in facts:
data_cells = row['dataCells']
case_owner = data_cells[0]['label']
m_account_number = data_cells[1]['value']
case_number = data_cells[2]['label']
report_label = data_cells[3]['label']
report_id = data_cells[3]['value']
csv_writer.writerow([
case_owner,
m_account_number,
case_number,
report_label,
report_id,
])
csv_file.close()
print(blist)