jsonpath_rw操作json
from jsonpath_rw import parse def get_key_from_data(key,data): # 定义匹配规则 json_expr=parse(key) result=json_expr.find(data) # [match.value for match in male][0] return [match.value for match in result] if __name__ == '__main__': # key="msg" # key="data[*].uid" key="$..uid" data={"code":"00","msg":"success","data":[ {"uid":"1","name":"zs","age":11}, {"uid": "2", "name": "ls", "age": 12}, {"uid": "3", "name": "ww", "age": 13} ]} print(get_key_from_data(key,data))