# -*-coding:utf-8 -*- # # --------------------------------------------------------------------------- # ProjectName: test # FileName: read_json.py # Author: zhang # Datetime: 2024/11/5 下午7:20 # Description: # # --------------------------------------------------------------------------- from APIAutoTest_v3_1 import log import json import os def read_json(file_path): """读取json文件,将json文件的内容序列化为python对象在返回""" log.info(f"执行Read_json函数,读取json文件,文件路径为{file_path}") if isinstance(file_path, str) and os.path.isfile(file_path) and file_path.endswith(".json"): with open(file_path, "r", encoding="utf-8") as f: try: return json.load(f) except Exception as e: log.error(f"执行Read_json函数,读取json文件失败,错误类型为{type(e)},错误信息为{e}") else: log.error(f"执行Read_json函数,读取json文件失败,文件路径不合法,文件路径为{file_path}") raise FileNotFoundError(f"文件路径不合法,文件路径为{file_path}") if __name__ == '__main__': print(read_json(r"C:\Users\zyh\Desktop\test_case\APIAutoTest_v3_1\data_config\z1_data\case_data1.json"))