但是需要注意的是,python的库并不是jsonpath(还真有这个库,但是不知如何使用,官方也没有给出python的使用文档),真正在python中可以使用的库是:jsonpath-rw
>>> from jsonpath_rw import jsonpath, parse>>> json_obj = {"student":[{"male":176,"female":162},{"male":174,"female":159}]}>>> jsonpath_expr = parse("student[*].male")>>> male = jsonpath_expr.find(json_obj)>>> male #返回的是list,但是不是我们想要的值[DatumInContext(value=176, path=Fields('male'), context=DatumInContext(value={'male': 176, 'female': 162}, path=<jsonpath_rw.jsonpath.Index object at 0x000001C6B95109B0>, context=DatumInContext(value=[{'male': 176, 'female': 162}, {'male': 174, 'female': 159}], path=Fields('student'), context=DatumInContext(value={'student': [{'male': 176, 'female': 162}, {'male': 174, 'female': 159}]}, path=This(), context=None)))), DatumInContext(value=174, path=Fields('male'), context=DatumInContext(value={'male': 174, 'female': 159}, path=<jsonpath_rw.jsonpath.Index object at 0x000001C6B9510588>, context=DatumInContext(value=[{'male': 176, 'female': 162}, {'male': 174, 'female': 159}], path=Fields('student'), context=DatumInContext(value={'student': [{'male': 176, 'female': 162}, {'male': 174, 'female': 159}]}, path=This(), context=None))))]#想要获取值,要用如下方法>>> [match.value for match in male][176, 174]