模块安装:pip3 install jsonpath
import jsonpath
ok_req={ "version": "9.0.0", "is_test": True, "store": "", "urs": "", "device": { "os": "android", "imei": "99001062198893", "device_id": "CQliMWEyYTEzNTYyYzk5MzJmCTJlNmY3Zjkx", }, "adunit": { "category": "VIDEO", "location": "1", "os": "ios", "blacklist": "" }, "ext_param":{ "is_start" : 0, "vId":"VW0BRMTEV" } } print(jsonpath.jsonpath(ok_req,'$.ext_param')) #找key为ext_param的值,返回类型list ----精准查询 print(jsonpath.jsonpath(ok_req,'$.device.os')) #找device下的key为os的值,返回类型list ---精准查询 print(jsonpath.jsonpath(ok_req,'$..os')) #找字典中的key为os的所有值,返回类型list ----模糊查询 打印结果: [{'is_start': 0, 'vId': 'VW0BRMTEV'}] ['android'] ['android', 'ios']