python之Jsonpath模块

import jsonpath
d = {
        "error_code": 0,
        "stu_info": [
                {
                        "id": 314,
                        "name": "矿泉水",
                        "sex": "男",
                        "age": 18,
                        "addr": "北京市昌平区",
                        "grade": "摩羯座",
                        "phone": "18317155663",
                        "gold": 14405
                },
            {
                "id": 314,
                "name": "矿泉水",
                "sex": "男",
                "age": 18,
                "addr": "北京市昌平区",
                "grade": "摩羯座",
                "phone": "18317155664",
                "gold": 14405
            }
            
        ]}
result = jsonpath.jsonpath(d,'$.stu_info[0].id') #取出stu_info一个字典key的值 id = 314
result = jsonpath.jsonpath(d,'$..id') #stu_info 中所有的id 314,315
print(result)

python之Jsonpath模块_第1张图片

你可能感兴趣的:(python基础)