21 lines
460 B
Python
21 lines
460 B
Python
# -*- coding:utf-8 -*-
|
|
# @Author len
|
|
# @Create 2023/10/24 20:26
|
|
|
|
import os
|
|
import json
|
|
|
|
# 读取JSON文件
|
|
with open('your_json_file.json', 'r') as f:
|
|
data = json.load(f)
|
|
|
|
# 获取文件名
|
|
image_path = data['imagePath']
|
|
filename = os.path.basename(image_path)
|
|
|
|
# 修改"imagePath"字段为只有文件名的形式
|
|
data['imagePath'] = filename
|
|
|
|
# 保存修改后的JSON文件
|
|
with open('modified_json_file.json', 'w') as f:
|
|
json.dump(data, f, indent=4) |