![](/img/trans.png)
[英]How to extract nested elements in JSON response using JSON extractor
[英]How to extract nested elements in JSON response using JSON extractor in JMeter
我想根據嵌套 JSON 響應中的條件提取一個元素。 使用下面廣泛搜索的示例,我想提取“Foo Bar”創作的所有書籍的 storeid:
{
"store": {
"storeId": 1
"book": [
{
"category": "reference",
"author": [
{
"Nigel Rees",
"Foo Bar"
}
],
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": [
{
"Evelyn Waugh"
}
],
"title": "Sword of Honour",
"price": 12.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
我嘗試使用如下表達式: $.store[?(@..author=='Foo Bar')].storeId
我還嘗試使用以下方法查看是否有任何商店返回: $.store[*].book[?(@.author=='Foo Bar')]
但沒有返回結果......請幫助。 謝謝!
您生成的不是有效的 JSON ,因此您將無法在其上使用 JSON Extractor。
如果你修改這個你甚至不能正確復制和粘貼以包含你的storeId
的好例子:
{
"store": {
"storeId": 1,
"book": [
{
"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
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
您將能夠使用以下表達式提取其中一位作者是Nigel Rees
的storeId
:
$.store[?(@.book[?(@.author=="Nigel Rees")])].storeId
演示:
更多信息:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.