import os
import json
def set_image_data_to_null(directory):
for filename in os.listdir(directory):
if filename.endswith('.json'):
file_path = os.path.join(directory, filename)
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
将 imageData 设置为 None,在JSON文件中会显示为 null
if 'imageData' in data:
data['imageData'] = None
保存修改后的文件
with open(file_path, 'w', encoding='utf-8') as file:
json.dump(data, file, indent=4)
替换以下路径为你的JSON文件所在的文件夹路径
directory_path = 'path_to_your_directory'
set_image_data_to_null(directory_path)