放心的GPATH表达方式是什么

发布于 2025-02-09 01:02:07 字数 1348 浏览 3 评论 0原文

我试图使用过滤条件创建GPATH表达式,以返回“ mynotes”在'“ my-type”'''

'''data.my-node.nodes时。 findall {it.'my-type'=='常规'}。'my-nodes'''''

但无法从下面的json获得响应

{
   "data": {"my-node":    [
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "abcdefg"}],
            "my-type": "GENERAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "abcdefg"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "oiugitoirtuhou"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "ifuoirjhihj"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "idfgdiufgdhsfuihdf"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "iydfgsigdfgdgidsf"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      }
   ]}
}

I have tried to create GPath expression with filter criteria to return "my-notes" in list of object when '"my-type"' is SPECIAL

like : '"data.my-node.nodes.findAll{it.'my-type'=='GENERAL'}.'my-nodes'"'

but unable to get response from the below json

{
   "data": {"my-node":    [
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "abcdefg"}],
            "my-type": "GENERAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "abcdefg"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "oiugitoirtuhou"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "ifuoirjhihj"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "idfgdiufgdhsfuihdf"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      },
            {
         "nodes": [         {
            "my-nodes": [{"my-note": "iydfgsigdfgdgidsf"}],
            "my-type": "SPECIAL"
         }],
         "my-instruction": null
      }
   ]}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

有深☉意 2025-02-16 01:02:07

GPATH语法是

List<?> value = JsonPath.from(res).get("data['my-node'].nodes.flatten().findAll{it.'my-type'=='GENERAL'}['my-nodes'].flatten()");
System.out.println(value);
//[{my-note=abcdefg}]
  • 首先,使用['key-abc']对键包含特殊字符。
  • 其次,使用flatten()方法将2D数组制成1D数组。

The GPath syntax is

List<?> value = JsonPath.from(res).get("data['my-node'].nodes.flatten().findAll{it.'my-type'=='GENERAL'}['my-nodes'].flatten()");
System.out.println(value);
//[{my-note=abcdefg}]
  • First, use ['key-abc'] for keys contain special characters.
  • Second, use flatten() method to make 2D array to 1D array.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文