简体   繁体   中英

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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