代码之家  ›  专栏  ›  技术社区  ›  user3616614

JsonPath-通过过滤另一个节点的存在来选择一个节点

  •  -1
  • user3616614  · 技术社区  · 8 年前

    http://jsonpath.com

    {
        "Portfolio":{
            "Website 1":{
                "url":"https://www.website1.com",
                "components":[
                    "component1",
                    "component2",
                    "component3"
                ]
            },
            "Website 2":{
                "url":"https://www.website2.com",
                "components":[
                    "component5",
                    "component1",
                    "component4"
                ]
            }
        }
    }
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   Kirk Larkin    8 年前

    $.Portfolio[?(@.components.indexOf('component1') !== -1)].url
    

    提到 here ?() 允许您将JavaScript代码作为过滤器运行。

    我鼓励你确切地了解这是在做什么,并在你下一次在这里张贴自己的问题尝试。