def Dict_get(dicts, objkey, instructions=None,default=None):
tmp = dicts
if isinstance(tmp, dict):
for k, v in tmp.items():
if k == objkey:
return v
else:
if isinstance(v,(dict,list,tuple,set)):
ret = Dict_get(v, objkey, default)
if ret is not default:
logging.info(f'获取{instructions}为:{ret}')
return ret
else:
if isinstance(tmp, list):
for k in tmp:
if k == objkey:
return [k]
else:
if isinstance(k, (dict, list, tuple, set)):
ret = Dict_get(k, objkey, default)
if ret is not default:
logging.info(f'获取{instructions}为:{ret}')
return ret
return default
#用于接口自动化测试 ,断言时或获取json结果中某个key的值,根据需要可以改变类型
欢迎来到testingpai.com!
注册 关于