Files
ModelTrainingPython/FC_ML_Tool/Serialization.py
2025-10-17 14:59:16 +08:00

23 lines
616 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
from typing import Dict, Any
def parse_json_file(file_path: str) -> Dict[str, Any]:
"""
读取并解析JSON文件为Python对象
参数:
file_path: JSON文件路径
返回:
解析后的Python字典对象
"""
try:
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
return data
except FileNotFoundError:
print(f"错误:文件 {file_path} 未找到")
except json.JSONDecodeError as e:
print(f"JSON解析错误{e}")
except Exception as e:
print(f"发生错误:{e}")