【问题标题】:JSONPath issu returning value using a filterJSONPath 使用过滤器发出返回值
【发布时间】:2020-10-26 21:04:24
【问题描述】:

我有以下 json,我无法使用过滤器选择其中一个值。具体来说,我想返回“POS_Undeclared”

{"wd:Program_of_Study_Reference": {
                                                    "wd:ID": [
                                                        {
                                                            "@wd:type": "WID",
                                                            "$": "123456789abcde"
                                                        },
                                                        {
                                                            "@wd:type": "Program_of_Study_ID",
                                                            "$": "POS_Undeclared"
                                                        }
                                                    ]
                                                }
}

这个 jsonpath $.wd:Program_of_Study_Reference.wd:ID[1].$ 给了我我需要的东西,但我不能指望顺序一致甚至存在,因此不能使用 [1] 。

我似乎无法使用像 @wd:type == Program_of_Study_ID 这样的过滤器。我猜这是 @ 和/或 : 搞砸了我的语法。

如何过滤以获得值 POS_Undeclared ?

【问题讨论】:

  • 我打算写,我猜是 $、@ 或 : 字符弄乱了我的语法。
  • 我认为是 $,因为我能够让这个工作:$.wd:Program_of_Study_Reference.wd:ID.[?(@['@wd:type'] == " Program_of_Study_ID")]

标签: json jsonpath json-path-expression


【解决方案1】:

尝试使用

$.wd:Program_of_Study_Reference.*[?(@['@wd:type'] == "Program_of_Study_ID")].$

【讨论】:

  • 感谢您的回复杰克。我原以为这会起作用,但 JSONPath 评估器带回的是:[ { "@wd:type": "Program_of_Study_ID", "$": "POS_Undeclared" } ]
  • @ACesario I tested it here,在 Jayway 选项卡下。
猜你喜欢
  • 2023-03-09
  • 2020-05-26
  • 2022-11-25
  • 2015-12-03
  • 1970-01-01
  • 2011-01-01
  • 2017-12-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多