37 lines
1.5 KiB
Python
37 lines
1.5 KiB
Python
import json
|
|
import os
|
|
|
|
# 目录路径
|
|
directory = "output"
|
|
|
|
# 确保目录存在
|
|
if not os.path.exists(directory):
|
|
os.makedirs(directory)
|
|
# 读取多个 JSON 文件并合并
|
|
def merge_json_files(file_list, output_file):
|
|
merged_data = []
|
|
|
|
# 遍历每个文件
|
|
for file in file_list:
|
|
with open(f"data/{file}", 'r', encoding='utf-8') as f:
|
|
data = json.load(f) # 读取 JSON 文件
|
|
merged_data.extend(data) # 合并数据
|
|
|
|
# 将合并后的数据写入新文件
|
|
with open(output_file, 'w', encoding='utf-8') as f:
|
|
json.dump(merged_data, f, ensure_ascii=False, indent=4)
|
|
|
|
# 文件列表
|
|
files = ['互联网查询.json','天气查询.json','知识问答.json','作业考勤人数.json', '周计划作业内容.json',
|
|
'周计划数量查询.json','施工人数.json','日计划作业内容.json','日计划数量查询.json',
|
|
'页面切换.json','通用对话.json','作业面查询.json','班组人数查询.json','班组数查询.json','作业面内容.json',
|
|
'班组详情.json','工程进度查询.json','人员查询.json','分公司查询.json','工程数量查询.json',
|
|
'工程详情查询.json','项目部数量查询.json','建管单位数量查询.json','建管单位详情.json','分包单位数量查询.json',
|
|
'分包单位详情.json']
|
|
output_file = 'output/merged_data.json'
|
|
|
|
# 执行合并
|
|
merge_json_files(files, output_file)
|
|
|
|
print("合并完成,结果保存在 'merged_data.json'")
|