赞
踩
import json with open("postman_collection.json", "r+", encoding="utf-8") as f: d = json.loads(f.read()) result = [] for items in d["item"]: if 'item' in items.keys(): name = items['name'] for item in items['item']: if 'item' in item.keys(): pass else: # 接口名称 modelName = item['name'] # print() # 请求路由 path = item['request']['url']['raw'] # model/verifyapi/verifyIdcard # print(path) # 请求方法 # method = item['request']['method'] # POST # print(method) # 传参 parms = item['request']['body']['raw'] # 取出来的是字符串,想提取body里面的参数需转成字典 # parms_dist = ast.literal_eval(parms) #用ast.literal_eval转换字典执行过程中会报错,故用json.load转字典 parms_dist = json.loads(parms) # 转字典 print(modelName, "\t", f"/{name}/{modelName}", "\t", path, "\t", parms_dist) # 产品编号 # modelNo = parms_dist["prodId"] # print(modelNo) # print("") else: # 接口名称 modelName = items['name'] # print(modelName) # 请求路由 path = items['request']['url']['raw'] # model/verifyapi/verifyIdcard # print(path) # 请求方法 # method = items['request']['method'] # POST # print(method) # 传参 parms = items['request']['body']['raw'] # 取出来的是字符串,想提取body里面的参数需转成字典 # parms_dist = ast.literal_eval(parms) #用ast.literal_eval转换字典执行过程中会报错,故用json.load转字典 parms_dist = json.loads(parms) # 转字典 print(modelName, "\t", modelName, "\t", path, "\t", parms_dist) # 产品编号 # modelNo = parms_dist["prodId"] # print(modelNo) # print("")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。