Embedded_game/修改json文件路径.py

21 lines
460 B
Python
Raw Normal View History

2025-01-02 12:48:11 +08:00
# -*- 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)