read_json.py 754 Bytes
Newer Older
duqing committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# -*-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("文件路径错误")