# -*- coding:utf-8 -*- # python 3.10 import json,shutil,os # 当前目录 curPath = os.getcwd() imgpath = curPath + '/img/' jsonpath = curPath + '/goods.json' # 读取json文件 with open(jsonpath, 'r', encoding='utf-8') as file: data = json.load(file) goodid = 0 def traverse_json(data): if isinstance(data, dict): for key, value in data.items(): print(key, ':') traverse_json(value) elif isinstance(data, list): for item in data: traverse_json(item) else: print(data) if type(data) == int: global goodid goodid = data else: if os.path.exists(imgpath+data+'.png'): os.rename(imgpath+data+'.png', imgpath+str(goodid)+'.png') traverse_json(data)