# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   PythonProject_1
# FileName:      read_json.py
# Author:       H_M
# Datetime:     2024/9/3 18:03
# Description:
# ---------------------------------------------------------------------------
import json
import os

from MyApiAutoTest_v3 import log


def read_json(file_path):
    """读取json文件，返回python对象"""
    if isinstance(file_path, str):
        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.load(f)
            except Exception as e:
                log.error(f"读取json文件产生错误，文件路径为{file_path}, 错误为：{e}")
                raise e
        else:
            log.error("不是一个json文件")
    else:
        log.error("文件路径不是一个字符串")

