def isJson(jsonstr):
try:
json.loads(jsonstr.text)
return True
except Exception as e:
return False
def checktype(responsejson):
"""
传入json并返回json数据类型
:param responsejson:
:return: 返回返回值参数及类型
"""
typelist = ['int', 'str', 'list', 'bool', 'NoneType', "float"]
#遍历返回结果的键值对
for itemkey, itemvalue in responsejson.items():
itemtype = str(type(itemvalue))
if itemtype in typelist:
itemvalue = itemtype
responsejson[itemkey] = itemvalue
elif itemtype == 'dict':
itemvalue = itemvalue
checktype(itemvalue)
responsejson[itemkey] = itemvalue
return responsejson
python接口测试断言返回值json格式和数据类型
最新推荐文章于 2025-02-13 13:57:45 发布