图片解析应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
695 B

  1. #coding:utf8
  2. import json
  3. from jsonpath_ng import jsonpath, parse
  4. import logging
  5. import traceback
  6. # 初始化日志
  7. logger = logging.getLogger(__name__)
  8. def get_value(data,formula):
  9. '''
  10. :param data:
  11. :param formula:
  12. :return:
  13. '''
  14. try:
  15. datas = str(formula).split(':')
  16. # 创建 JsonPath 表达式
  17. expr = parse(datas[1])
  18. # 使用表达式来选择 JSON 元素
  19. match = [match.value for match in expr.find(json.loads(data[datas[0]]))]
  20. return match[0]
  21. except Exception as e:
  22. traceback.print_exc()
  23. logger.error(f"动态获取数据失败: {e}")
  24. return None