名单的跑步者

发布于 2025-02-07 16:53:10 字数 536 浏览 1 评论 0原文

我正在努力使我的跑步者起作用。 在这里,我的方法的原始主体

{
    "itemList": [
        "{{items}}"
    ],
    "storeType": 7,
    "storeNum": [
        "{{store}}"
    ]
}

我想使用一个包含该行的CSV文件,例如此

商店,项目

115,“ 1097456,85591,716027”“

问题是,我不知道如何将我从文件中获得的字符串格式化” 1097456,85591,716027“使我的身体起作用。

我的身体应该看起来就是这样:

{
    "itemList": [1097456,855591,716027],
    "storeType": 7,
    "storeNum": [115]
}

如果我从“ {{items}}}”中删除双引号,我会遇到JSON错误。 我迷路了,开始认为这是不可能的:(

欢迎任何帮助。

谢谢

I'm struggling to make my runner works.
Here the raw body of my method

{
    "itemList": [
        "{{items}}"
    ],
    "storeType": 7,
    "storeNum": [
        "{{store}}"
    ]
}

i want to use a csv file containing line like this

store,items

115,"1097456,855591,716027"

The issue is, i don't know how to format the string i got from the file "1097456,855591,716027" to make my body works.

My body should look's like that:

{
    "itemList": [1097456,855591,716027],
    "storeType": 7,
    "storeNum": [115]
}

If i remove the double quote from "{{ITEMS}}" i got a json error.
I'm lost and start to think this is impossible :(

Any help is welcome.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡笑忘祈一世凡恋 2025-02-14 16:53:10

步骤1:更改请求主体

{
    "itemList": {{items}},
    "storeType": 7,
    "storeNum": {{stores}}
}

步骤2:在预要求选项卡中写代码以将字符串转换为数字列表。

let stores = readInput("store");
let items = readInput("item");

pm.environment.set("stores", JSON.stringify(stores));
pm.environment.set("items", JSON.stringify(items));

function readInput(header){
    let input = pm.iterationData.get(header).toString();
    let fields = [];

    if (input.includes(",")) {
        inputs = input.split(",");
        fields = inputs.map(x => parseInt(x));
    } else {
        fields.push(parseInt(input));
    }  
    return fields;
}

CSV文件:

“在此处输入图像描述”

样本请求主体:

”在此处输入图像描述”

Step 1: Change the request body

{
    "itemList": {{items}},
    "storeType": 7,
    "storeNum": {{stores}}
}

Step 2: Write code in Pre-Request tab to convert String to a list of number.

let stores = readInput("store");
let items = readInput("item");

pm.environment.set("stores", JSON.stringify(stores));
pm.environment.set("items", JSON.stringify(items));

function readInput(header){
    let input = pm.iterationData.get(header).toString();
    let fields = [];

    if (input.includes(",")) {
        inputs = input.split(",");
        fields = inputs.map(x => parseInt(x));
    } else {
        fields.push(parseInt(input));
    }  
    return fields;
}

CSV file:

enter image description here

Sample request body:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文