我想從json數組中提取第一個元素。下面提到的是json數組Jmeter:如何從json數組中提取第一個元素
[
{
"cohortDefinition": {
"Key": 1151,
"id": 1798,
"srcId": "3526",
"pcKey": -1,
"userName": "CHROME_USER",
"name": "JMeter2017-01-06-1483749546167",
"Type": "SUBJECT",
"tool": "CB",
"count": 32757,
"extractionStatus": "",
"dateCreated": "2017-05-10T17:48:45Z"
},
"datasource": {
"id": 2,
"name": "health",
"subjectCount": 116352
},
"project": {
"id": 747,
"name": "Jmeter Project"
}
},
{
"cohortDefinition": {
"Key": 1150,
"id": 1796,
"srcId": "3525",
"pcKey": -1,
"userName": "CHROME_USER",
"name": "JMeter2016-10-27-1477620919644",
"Type": "SUBJECT",
"tool": "CB",
"count": 32757,
"extractionStatus": "",
"dateCreated": "2017-05-10T16:57:11Z"
},
"datasource": {
"id": 2,
"name": "health",
"subjectCount": 116352
},
"project": {
"id": 747,
"name": "Jmeter Project"
}
}
]
從上面的json我想提取第一個值,即。 srcId「:‘3526’ 我試圖做在JMeter中提取下面的表達式
$..cohortDefinition.srcId[1]
但是它無法正常工作。如果有誰知道如何做到這一點,請不要讓我知道
使用'$ .. cohortDefinition.srcId'在' JSON路徑提取器「。 'myVar_1'將會有第一個'srcId'。 –
我試過這個選項。這導致3526和3525 – Sachetan
是的。您需要在您的測試計劃中使用'myVar_1',它將檢索第一個'srcId'。 –