简体   繁体   English

从响应体中解析数据数组 json

[英]Parsing data array from response body json

My task is to create a new record in the database using a unique identifier.我的任务是使用唯一标识符在数据库中创建一条新记录。 I have to contact the service using the GET method, from which I get a set of unique identifiers, then write them in the collection variables and then use them in my tests.我必须使用 GET 方法联系服务,从中我得到一组唯一标识符,然后将它们写入集合变量中,然后在我的测试中使用它们。 I get the answer in this form.我以这种形式得到答案。 I understand that I have to parse the array of answers and write the result in a variable.我知道我必须解析答案数组并将结果写入变量。

response body:响应体:

响应体

starting parse:开始解析:

开始解析

I don't know how correctly I solved my question, but it works the way I need it to.我不知道我如何正确地解决了我的问题,但它按照我需要的方式工作。 The answer is parsed into individual identifiers:答案被解析为单独的标识符:

var jsonData = JSON.parse(responseBody);
pm.collectionVariables.set("dealRef1", jsonData[0]);
pm.collectionVariables.set("dealRef2", jsonData[1]);
pm.collectionVariables.set("dealRef3", jsonData[2]);
pm.collectionVariables.set("dealRef4", jsonData[3]);
pm.collectionVariables.set("dealRef5", jsonData[4]);

Response Body:响应主体:

[
"1BPMPOST9O5L0F8E9NPX",
"1BPMPOSTI5I10F8E9NPF",
"1BPMPOST0LFP0F8E9NQ5",
"1BPMPOSTIBP80F8E9NQI",
"1BPMPOSTQILO0F8E9NQC"
]

аnd written to Collection Variables, which I then call in my further tests.并写入集合变量,然后我在进一步的测试中调用它。

Collection Variables:集合变量:

dealRef1 - 1BPMPOST9O5L0F8E9NPX
dealRef1 - 1BPMPOSTI5I10F8E9NPF
dealRef1 - 1BPMPOST0LFP0F8E9NQ5
dealRef1 - 1BPMPOSTIBP80F8E9NQI
dealRef1 - 1BPMPOSTQILO0F8E9NQC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM