我有以下JSON结构:
[
{ "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
它给我的输出是:
[
"Sayings of the Century",
"Sword of Honour",
"Moby Dick",
"The Lord of the Rings"
]我试过这样做:
$.*.(@..title=‘指环王’)
但这不起作用。拜托有人能帮我吗?
提前感谢!
发布于 2022-02-11 18:52:58
原谅我之前的回答。我不知道jsonpath是一回事。我找到了你的答案:
$[?(@.title == 'The Lord of the Rings')]原因是,由于对象位于根元素中,所以您已经尝试使用@.title在元素中选择标题。当您使用$.[*]选择所有元素时,您的级别已经太低,无法按标题查找。
https://stackoverflow.com/questions/71085083
复制相似问题