import json
body={'discountPrice':{'1':'5.4847','59':'5.1938','100':'4.9030'}}
#将dict类型的数据转换成str
jsDumps=json.dumps(body)
jsLoads = json.loads(jsDumps)
if ('discountPrice' in jsLoads) :
print('存在')
else:
print('不存在')
#循环获取key和value
for r in jsLoads['discountPrice']:
print(f'qty:{r} price{jsLoads["discountPrice"][r]}')
python中判断json的key是否存在,以及动态获取key和value
于 2022-12-30 16:11:00 首次发布