{
"store": {
"tag_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
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
我只希望提取tag_book和自行车。我不需要tag_book和Bicycle的值。
能请您解释一下如何提取它。
答案 0 :(得分:1)
将以下Groovy代码放入“脚本”区域:
new groovy.json.JsonSlurper().parse(prev.getResponseData()).store.eachWithIndex { entry, i ->
vars.put('var_' + (i + 1), entry.getKey())
}
其中:
prev
代表上一个SampleResult vars
用于JMeterVariables 这将生成以下JMeter Varibales:
var_1=tag_book
var_2=bicycle
您将可以在需要时将它们用作${var_1}
,${var_2}
等。