basic-auto-test/util/basic/analysis_json.py

24 lines
764 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.

# -*- coding: utf-8 -*-
# -------------------------------
# @文件json_utils.py
# @时间2024/5/17 下午4:34
# @作者caiweichao
# @功能描述:解析 json
# -------------------------------
import json
from jsonpath import jsonpath
from util.basic.log import Log
from util.customize_exception import AnalysisError
def analysis_json(json, json_path_rule: str):
try:
if jsonpath(json, json_path_rule):
Log.info(f"json解析结果为{jsonpath(json, json_path_rule)[0]}")
return jsonpath(json, json_path_rule)[0]
else:
raise AnalysisError(f"json解析异常解析规则:{json_path_rule}")
except TypeError:
raise AnalysisError(f"json解析异常解析规则:{json_path_rule}")