我在 Postman 中进行了一个测试,在那里我执行了一个 post 请求并需要解析 json 响应
I have a test in Postman where I do a post request and need to parse the json response
响应如下所示:
"aPIProxy" : [ {
"name" : "SFDC-UpdateLoginTime-v1",
"revision" : [ {
"configuration" : {
"basePath" : "/",
"steps" : [ ]
},
"name" : "1",...some attributes}]
我需要得到类似的东西:
and i need to get something like :
"name" : "SFDC-UpdateLoginTime-v1"
"name" : "1"
对于多次出现的 json 文件.
for a multiple occurrence json file.
下面的邮递员脚本可能会对你有所帮助.
The below postman script might help you.
var jsonData = JSON.parse(responseBody);
var jsonNamesData = jsonData.aPIProxy;
console.log(jsonNamesData);
var parsedData = "";
for(var i=0;i<jsonNamesData.length;i++){
parsedData = parsedData +""name" : "" +jsonNamesData[i].name+"", ";
console.log(""name" : "" +jsonNamesData[i].name+""");
}
console.log(parsedData);
postman.setEnvironmentVariable("parsedNamesResponse", parsedData); // updating parsed data to the environment variable parsedNamesResponse