首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用JSONPath过滤单个字符串?

如何使用JSONPath过滤单个字符串?
EN

Stack Overflow用户
提问于 2022-02-11 18:42:34
回答 1查看 103关注 0票数 0

我有以下JSON结构:

代码语言:javascript
复制
    [ 
        { "category": "reference",
          "author": "Nigel Rees",
          "title": "Sayings of the Century",
          "price": 8.95
        },
        { "category": "fiction",
          "author": "Evelyn Waugh",
          "title": "Sword of Honour",
          "price": 12.99
        },
        { "category": "fiction",
          "author": "Herman Melville",
          "title": "Moby Dick",
          "isbn": "0-553-21311-3",
          "price": 8.99
        },
        { "category": "fiction",
          "author": "J. R. R. Tolkien",
          "title": "The Lord of the Rings",
          "isbn": "0-395-19395-8",
          "price": 22.99
        }
    ]

我只想要一个包含“指环王”标题的东西

如果我输入:

$.*.title

它给我的输出是:

代码语言:javascript
复制
[
 "Sayings of the Century",
 "Sword of Honour",
 "Moby Dick",
 "The Lord of the Rings"
]

我试过这样做:

$.*.(@..title=‘指环王’)

但这不起作用。拜托有人能帮我吗?

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-11 18:52:58

原谅我之前的回答。我不知道jsonpath是一回事。我找到了你的答案:

代码语言:javascript
复制
$[?(@.title == 'The Lord of the Rings')]

原因是,由于对象位于根元素中,所以您已经尝试使用@.title在元素中选择标题。当您使用$.[*]选择所有元素时,您的级别已经太低,无法按标题查找。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71085083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档