我正在使用REST API,输出来自响应数据中的json。我希望以CSV格式自动保存该数据。
{
"suggestedLocations":[
{
"distance":521,
"eLoc":"JEU3UB",
"email":"",
"entryLatitude":28.544811,
"entryLongitude":77.267884,
"keywords":[
"PRKWPM"
],
"landlineNo":"",
"latitude":28.544832,
"longitude":77.2675620000001,
"mobileNo":"",
"orderIndex":1,
"placeAddress":"Shyam Nagar,New Delhi,Delhi",
"placeName":"Banarsidas Chandiwala Institute of Medical Science Hospital Parking",
"type":"POI"
},
{
"distance":558,
"eLoc":"4E2C94",
"email":"",
"entryLatitude":28.544919,
"entryLongitude":77.267829,
"keywords":[
"COMGAT"
],
"landlineNo":"",
"latitude":28.5444890000001,
"longitude":77.2676670000001,
"mobileNo":"",
"orderIndex":2,
"placeAddress":"Sri Maa Anandamayi Ashram Marg,Shyam Nagar,New Delhi,Delhi",
"placeName":"Banarsidas Chandiwala Hospital Gate No 2",
"type":"POI"
},
{
"distance":607,
"eLoc":"JU2KU8",
"email":"",
"entryLatitude":28.54492,
"entryLongitude":77.267829,
"keywords":[
"HLTHSP"
],
"landlineNo":"+911149020301",
"latitude":28.5441200000001,
"longitude":77.266806,
"mobileNo":"",
"orderIndex":3,
"placeAddress":"Kalkaji Address Chandiwala Estate, Maa Anandmai Ashram Marg, Kalkaji",
"placeName":"Banarsidas Chandiwala Institute of Medical Science Hospital",
"type":"POI"
},
{
"distance":876,
"eLoc":"7YURV9",
"email":"",
"entryLatitude":28.557416,
"entryLongitude":77.266518,
"keywords":[
"SHPCOM"
],
"landlineNo":"",
"latitude":28.5572960000001,
"longitude":77.2663660000001,
"mobileNo":"",
"orderIndex":4,
"placeAddress":"Max House 1, Dr Jha Marg, Okhla",
"placeName":"ALPS Hospital Ltd",
"type":"POI"
},
{
"distance":1040,
"eLoc":"258S85",
"email":"",
"entryLatitude":28.54495,
"entryLongitude":77.258571,
"keywords":[
"HLTHSP"
],
"landlineNo":"",
"latitude":28.5450080000001,
"longitude":77.2584680000001,
"mobileNo":"",
"orderIndex":5,
"placeAddress":"D Block, Kalkaji Extension",
"placeName":"Kalkaji Hospital",
"type":"POI"
},
{
"distance":1049,
"eLoc":"11A8D2",
"email":"",
"entryLatitude":28.558332,
"entryLongitude":77.271274,
"keywords":[
"HLTHSP"
],
"landlineNo":"",
"latitude":28.5583580000001,
"longitude":77.2715460000001,
"mobileNo":"",
"orderIndex":6,
"placeAddress":"Zakir Bagh Apartment,Ishwar Nagar,New Delhi,Delhi",
"placeName":"Government Hospital",
"type":"POI"
},
{
"distance":1061,
"eLoc":"T1D2A4",
"email":"",
"entryLatitude":28.543885,
"entryLongitude":77.259128,
"keywords":[
"HLTHSP"
],
"landlineNo":"+911126439867, +911126437885, +911126419895",
"latitude":28.543983,
"longitude":77.2589550000001,
"mobileNo":"",
"orderIndex":7,
"placeAddress":"DD 15, Near Main Post office, Kalkaji",
"placeName":"Shubham Hospital",
"type":"POI"
},
{
"distance":1082,
"eLoc":"A20AL1",
"email":"",
"entryLatitude":28.544864,
"entryLongitude":77.25828,
"keywords":[
"HLTHSP"
],
"landlineNo":"",
"latitude":28.544673,
"longitude":77.2581950000001,
"mobileNo":"",
"orderIndex":8,
"placeAddress":"Thana Road, Near Chandra Gas Agency",
"placeName":"Irene Hospital",
"type":"POI"
},
{
"distance":1305,
"eLoc":"6X0RTW",
"email":"",
"entryLatitude":28.547451,
"entryLongitude":77.254602,
"keywords":[
"HLTHSP"
],
"landlineNo":"",
"latitude":28.547291,
"longitude":77.254686,
"mobileNo":"",
"orderIndex":9,
"placeAddress":"C 30-31, Nehru Enclave, Kalkaji Road, Block G, Near HDFC Bank ATM",
"placeName":"Triton Hospital",
"type":"POI"
},
{
"distance":1339,
"eLoc":"E19PBI",
"email":"",
"entryLatitude":28.56004,
"entryLongitude":77.274484,
"keywords":[
"PRKMLT"
],
"landlineNo":"",
"latitude":28.56003,
"longitude":77.2744980000001,
"mobileNo":"",
"orderIndex":10,
"placeAddress":"Escort Area,Masihgarh,New Delhi,Delhi",
"placeName":"Escort Hospital Multilevel Parking",
"type":"POI"
}
],
"explanation":{
"refLocation":"28.549513,77.267809",
"keyword":"hospital"
}
}
这是我的json数据。
答案 0 :(得分:2)
您可以通过执行以下步骤来保存所有JSON数据:
答案 1 :(得分:0)
我只能想到以下方法:
将下一行添加到 user.properties 文件(位于JMeter安装的“bin”文件夹中)
sample_variables=response
jmeter.save.saveservice.default_delimiter=|
添加JSR223 PostProcessor作为您要保存的响应数据的请求的子项,并将以下代码放入“脚本”区域:
vars.put('response', org.apache.commons.lang3.StringUtils.normalizeSpace(prev.getResponseDataAsString()))
在command-line non-GUI mode中运行您的测试:
jmeter -n -t test.jmx -l result.csv
测试完成后,您会看到包含“正常”JMeter指标和响应数据的result.csv
文件,作为最后一列名为response
参考文献:
答案 2 :(得分:-1)
您可以使用插件jsonpathextractor存储json resopnse数据。下面是进程链接。请查看它,让我知道任何问题。
https://octoperf.com/blog/2017/03/09/how-to-extract-data-from-json-response-using-jmeter/
要编写CSV文件,请使用以下视频来帮助您。 https://www.youtube.com/watch?v=eUtBQNd5YxE