由于最近在做接口自动化测试,其中用到的jsonpath尤其的多,所以进行记录。

1、先上一句代码

JSONPath.read(sourchJson, key);

2,sourchJson如下

{
    \"data\":{
        \"x\":[
            \"2018-12-19\",
            \"2018-12-20\"
        ],
        \"y\":{
            \"总体\":{
                \"col1\":[
                    146,
                    114
                ],
                \"col2\":[
                    [
                        146,
                        114
                    ],
                    [
                        0,
                        0
                    ]
                ]
            },
            \"0~90000\":{
                \"col1\":[
                    146,
                    114
                ],
                \"col2\":[
                    [
                        146,
                        114
                    ],
                    [
                        0,
                        0
                    ]
                ]
            }
        },
        \"cols_format_List\":[
            \"range\"
        ],
        \"z\":[
            \"用户注册\",
            \"获得金币\"
        ]
    },
    \"return_code\":0,
    \"return_message\":\"success\"
}

2、key就是我们刷选出我们需要的内容

比如我们设置key为:$.data.z.length()   可以得到值为2,

可以在线验证:http://jsonpath.com/,例如验证如下:

\"\"  

持续更新,可以在线多多尝试

收藏 打印