# -*-coding:utf-8 -*- # # --------------------------------------------------------------------------- # ProjectName: test61 # FileName: read_json.py # Author: lao_zhao # Datetime: 2024/7/12 14:08 # Description: # # --------------------------------------------------------------------------- import json import os def read_json(file_path): """读取json文件,并将json文件的内容序列化为python对象,再返回""" if os.path.isfile(file_path) and file_path.endswith(".json"): try: with open(file_path, mode="r", encoding="utf-8") as f: return json.loads(f.read()) except Exception as e: raise e else: raise FileNotFoundError("文件路径错误")