import com.jayway.jsonpath.JsonPath
def path = vars.get("BaseFilePath") + "/" + vars.get("FhirVersion") + "/Get/Patient/";
def newLine = System.getProperty('line.separator')
def response = prev.getResponseDataAsString()
//address
def addressCSV = new File(path + 'address.csv')
def addressCityCSV = new File(path + 'address-city.csv')
def addressCountryCSV = new File(path + 'address-country.csv')
def addressPostalCode = new File(path + 'address-postalcode.csv')
def addressState = new File(path + 'address-state.csv')
def replacement = {
if (it == ' ') {
'%20'
} else if (it == '/') {
'%2F'
} else if (it == '|')
{
'%7C'
}
else {
null
}
}
def address = JsonPath.read(response, '$..address')
address.each { eachAddress ->
eachAddress.each { subAddress ->
subAddress.get('line').each { line ->
addressCSV << line << newLine
}
addressCityCSV << subAddress.get('city').collectReplacements(replacement) << newLine
addressState << subAddress.get('state').collectReplacements(replacement) << newLine
addressPostalCode << subAddress.get('postalCode').collectReplacements(replacement) << newLine
addressCountryCSV << subAddress.get('country').collectReplacements(replacement) << newLine
}
}
Это код JSR223 в jmeter для извлечения значений из строки json
код работает до получения значений из JSON
значения subAddress.get ('city') = город Хокин и
subAddress.get ('postalCode') = http://hl7.org/fhir/sid/us-ssn|C999-87-3780
поэтому я хотел заменить белый символ:, /, | с% 20,% 2F,% 7C
и если строка не содержит ни одного из них, то запись строки в CSV-файл
Код не работает