当先锋百科网

首页 1 2 3 4 5 6 7

取出字典和数组的值

def getdict(dict1, values):
global values1, va # 定义全局变量
values1 = values
va=""
for k, v in dict1.items(): # 把字典的key和values变成数组
if k == values:
va = v
elif type(v).name == ‘dict’:
va = getdict(v, values1)
elif type(v).name == ‘list’:
va = getdict1(v, values1)
return va;

def getdict1(dict1, values):
for k in dict1:
va = getdict(k, values1)
return va;

dict= {“code”:0,“data”:{“termList”:[{“loanTerm”:3,“priceCode”:“2211”,“firstRepayDay”:30,“loanRate”:0.02,“feeStrategyId”:“1c99fe6d-6620-4110-9c2d-1f6c7a07a4e6”}],“availableLimit”:1000.00,“sshhs”:“true”,“bankCardInfo”:“中国工商银行(9057)”,“bankCardId”:“1118420900853604352”},“msg”:“成功”}
pa = getdict(dict,“feeStrategyId”)
print(pa);