解析 JSON 邮递员响应 [英] Parse JSON Postman response
本文介绍了解析 JSON 邮递员响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 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
这篇关于解析 JSON 邮递员响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文