[英]How to parse JSON array objects to string array objects in JMeter
我有以下 JSON。 我想要技術設置的 JSON 數組對象(在這種情況下是兩個對象,但可能會根據 API 響應而有所不同)到一個字符串數組中而不丟失任何文本,並希望循環通過字符串數組添加更多元素並形成一個新的 Z0ECD1F8D148並將新的 JSON 存儲在字符串變量中。
{
"data": {
"statusCode": 200,
"success": true,
"technicalSettings": [
{
"program": "C:/temp/abc.exe",
"actions": "9",
"file_name": "abc1",
"new_file_name": "newabc1",
"version": "2.0.0.0",
"product_name": "abc",
"description": "abc",
"eventdate": "20160601120000",
"autoVoiceProfile": {
"autoVoices": [
{
"autoVoiceLanguage": 0,
"autoVoiceMessage": [
{
"name": "AV1",
"duration": "1.200000",
"checksum": "2d4c44d142bc0391b980b8a103ab35cc23d8f7820895cb6025cf3c829139336c",
"fileName": "/usr/g/db/user_autoVoiceMsg7.aifc",
"id": 4
},
{
"name": "AV1",
"duration": "0.600000",
"checksum": "9538cf287d178964dcb57a05b7acbc00e04c800a9aaed0b22f5433d9dc79d80c",
"fileName": "/usr/g/db/user_autoVoiceMsg8.aifc",
"id": 4
},
{
"name": "AV2",
"duration": "2.800000",
"checksum": "050acdb345e079da1371623c9727bc16d166db0a0b47687ff93d736ddf37cde8",
"fileName": "/usr/g/db/user_autoVoiceMsg9.aifc",
"id": 5
},
{
"name": "AV2",
"duration": "4.100000",
"checksum": "c5a6a39df38505c0c22b75d9ea7781a1755e9c8c9f435e08034f579361ba751c",
"fileName": "/usr/g/db/user_autoVoiceMsg10.aifc",
"id": 5
}
]
}
],
"messagesitefilename": null
}
},
{
"program": "C:/temp/abc.exe",
"actions": "9",
"file_name": "abc2",
"new_file_name": "newabc2",
"version": "2.0.0.0",
"product_name": "abc",
"description": "abc",
"eventdate": "20160601120000",
"autoVoiceProfile": {
"autoVoices": [
{
"autoVoiceLanguage": 0,
"autoVoiceMessage": [
{
"name": "AV1",
"duration": "1.200000",
"checksum": "2d4c44d142bc0391b980b8a103ab35cc23d8f7820895cb6025cf3c829139336c",
"fileName": "/usr/g/db/user_autoVoiceMsg7.aifc",
"id": 4
},
{
"name": "AV1",
"duration": "0.600000",
"checksum": "9538cf287d178964dcb57a05b7acbc00e04c800a9aaed0b22f5433d9dc79d80c",
"fileName": "/usr/g/db/user_autoVoiceMsg8.aifc",
"id": 4
},
{
"name": "AV2",
"duration": "2.800000",
"checksum": "050acdb345e079da1371623c9727bc16d166db0a0b47687ff93d736ddf37cde8",
"fileName": "/usr/g/db/user_autoVoiceMsg9.aifc",
"id": 5
}
]
}
],
"messagesitefilename": null
}
}
],
"library": {
"version": 6,
"dmIdVersion": 5
}
},
"success": true,
"statusCode": 200,
"errorMessage": ""
}
我使用了 JSON 提取器,但由於數組對象包含多個“,”,因此在拆分為數組時失敗。
字符串 strPublishTechSettings = "${pPublishTechSettings_ALL}";
String[] PublishTechSettings = strPublishTechSettings.split(",");
不要將JMeter 函數或變量內聯到腳本中:
所以改變這一行:
String strPublishTechSettings = "${pPublishTechSettings_ALL}";
對此:
String strPublishTechSettings = "${pPublishTechSettings_ALL}";
in the above example vars
stands for JMeterVariables class instance, see JavaDoc for all available functions and Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on other JMeter API shorthands available to JSR223 Test Elements
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.