【问题标题】:Finding an element within an array that contains an array with a given string: JsonPath Java在包含具有给定字符串的数组的数组中查找元素:JsonPath Java
【发布时间】:2021-12-18 06:09:41
【问题描述】:

我是 JsonPath 的新手,正在使用 Java 端口 https://github.com/json-path/JsonPath

我有一个看起来像这样的 JSON 对象(实际上有很多条目,但为简洁起见,我删除了额外的条目)。

{
    "entry": [{
        "fullUrl": "urn:uuid:42627ef0-ea02-4323-8059-c8dfb6125314",
        "resource": {
            "resourceType": "Patient",
            "id": "42627ef0-ea02-4323-8059-c8dfb6125314",
            "meta": {
                "profile": [
                    "http://hl7.org/fhir/us/mcode/StructureDefinition/mcode-cancer-patient",
                    "http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
                ]
            },
            "text": {
                "status": "generated",
                "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Generated by <a href=\"https://github.com/synthetichealth/synthea\">Synthea</a>.Version identifier: v2.5.0-340-gabc9fc4a\n .   Person seed: -7528621318134299240  Population seed: 1586172373839</div>"
            }
        }
    }]
}

我正在尝试在配置文件数组中查找包含特定 URI 的条目。我似乎无法获得正确的语法以使其正常工作,并且在这一点上有点难过。

这是我迄今为止尝试过的,但没有成功。

$..entry[?(@.resource.meta[?(@.profile.indexOf('http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient') > -1)])]

任何指针都非常感谢!

【问题讨论】:

    标签: jsonpath


    【解决方案1】:

    Jayway Jsonpath 实现不支持indexOf。请改用in

    $..entry[?('http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient' in @.resource.meta.profile)]
    

    Jayway jsonpath 支持请参考Filter Operators

    在线测试工具:https://jsonpath.herokuapp.com/

    【讨论】:

      猜你喜欢
      • 2017-11-07
      • 1970-01-01
      • 1970-01-01
      • 2013-10-03
      • 2016-03-19
      • 1970-01-01
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多