from jsonpath_rw import jsonpath,parse
data = {
"error_code": 0,
"stu_info": [
{
"id": 309,
"name": "小白",
"sex": "男",
"age": 28,
"addr": "河南省济源市北海大道32号",
"grade": "天蝎座",
"phone": "18512572946",
"gold": 100
},
{
"id": 310,
"name": "小白",
"sex": "男",
"age": 28,
"addr": "河南省济源市北海大道32号",
"grade": "天蝎座",
"phone": "18516572946",
"gold": 100
}
]
}
json_expr = parse('stu_info[0].name')
male = json_expr.find(data)
print([math.value for math in male])
官方文档地址: https://github.com/kennknowles/python-jsonpath-rw