caseinfo=[{'name': '获取token','request': {'method': 'get', 'url': '/cgi-bin/token', 'headers': 'none','datas':{'grant_type': 'client_credential','appid': 'wx2ed6b772cc34974d', 'secret': 'aca6a76b0a57f9d32a90a716318d6736'}}, 'validate': 'none'}]
举例说明,近期在学习python的时候需要获取列表信息字段,列表里面嵌套了字典,则需要遍历操作执行
for item in caseinfo:for k,v in item.items():if type(v) !=dict:print(k,v)else:for k,v in v.items():if type(v) != dict:print(k, v)else:for k, v in v.items():print(k,v)
或者获取具体的某一个key值
for case in caseinfo:cases = case['request']['datas']print(cases)for key,value in cases.items():if type(value)==dict:for key, value in cases.items():print(key,value)else:print(key,value)