python中的字典数据读取

①字典中嵌套字典
res1={'content': {'age': '47岁', 'ageOne': 47, 'ageOneUnit': '1', 'ageTwo': '8', 'ageTwoUnit': '2', 'birthCode': '', 'birthday': '1974-09-09 00:00:00', 'birthdayStr': '1974-09-09', 'bloodTypeCode': '', 'bloodTypeStr': '', 'cardStatus': '1', 'code': 'H9069522', 'contactsName': '', 'contactsPhone': '','patientName': '测试',....}}

从这段响应值中拿到patientName的值:result = res1.get('content').get('patientName'),其中get()是从字典中获取对应key的value

②字典中嵌套list与字典
`res2={'content': {'docs': [{'addSource': [], 'consRoomCode': '103337', 'consRoomStr': '门诊诊室', 'departCode': '103255', 'departName': '测试门诊', 'doctorStr': 'xxx', 'dutyFullName': '测试医生', 'dzNum': 0, 'flag': '上', 'ordinarySource': [], 'regDoctorCode': 'xxxx', 'regDoctorschlCode': '42900125840', 'regTypeCode': '1006', 'regTypeStr': 'xxxx', 'shiftCode': '103043', 'shiftName': '上午', 'sourceDetailCode': '42900125840', 'syNum': 50}], 'type': '1'}, 'errorCode': '', 'errorMsg': '', 'status': 'OK'}`````

从这段响应值中拿到departCode的值:result=res2.get('content').get('docs')[0].get('departCode')

③给字典中指定key赋值
Body1['id'] =123这种格式就会赋值

posted @ 2022-05-16 11:18  sriver_dl  Views(1764)  Comments(0Edit  收藏  举报