JSONPath表达式可查看不同的键 [英] JSONPath expression to look inside different keys

查看:67
本文介绍了JSONPath表达式可查看不同的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RESTful API返回的JSON:

I have a JSON returned by a RESTful API:

{
    "0": {
        "id": "1484763",
        "name": "Name",
        "values": {
            "0": {
                "value": "Peter"
            }
        }
    },
    "1": {
        "id": "2584763",
        "name": "phone",
        "values": {
            "0": {
                "value": "45456456"
            }
        }
    }
}

如何编写提取电话号码值的JSONPath? (因此,在这种情况下为"45456456").使得问题更难解决的是,电话号码对象并不总是位于"1"键内.

How do I write a JSONPath that extracts a phone number value? (so in this case, "45456456"). What makes the problem harder, phone number object is not always inside "1" key.

推荐答案

尝试使用此JsonPath生成电话号码45456456

Try this JsonPath which results in phone number 45456456

$..[?(@.name = 'phone')].values.0.value

基本上,您必须在name == 'phone'处应用过滤器?(),然后使用常规的json路径.

Basically, you have to apply a filter ?() where name == 'phone' and then use normal json path.

尝试通过该链接

JsonPath表达式语法可以在此处找到.

JsonPath expression syntax can be found here.

这篇关于JSONPath表达式可查看不同的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆