jsonpath_rw:一个可以像写xpath一样写json的Python第三方库
首先安装:pip install jsonpath_rw
实例:
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])
版权声明:本文为mr_hui_原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。