1

我想从 Runner 集合中的数据文件 (JSON) 中获取一个对象数组。我在主应用程序中有我的集合,其中包含所有参数化的字段。

{
  "order": {
    "order_date": "{{order_date}}",
    "order_number": "{{order_number}}",
    "reference": "{{reference}}",
    "shipping_method": "{{shipping_method}}",
    "signature_required": {{signature_required}},
    "destination": {
      "name": "{{name}}",
      "phone": "{{phone}}",
      "email": "{{email}}",
      "company": "{{company}}",
      "building":"{{building}}",
      "street": "{{street}}",
      "suburb": "{{suburb}}",
      "city" : "{{city}}",
      "state": "{{state}}",
      "post_code": "{{post_code}}",
      "country": "{{country}}",
      "delivery_instructions": "{{delivery_instructions}}"
    },
    "items": [
      {
        "description": "My Item",
        "sku": "ItemA",
        "quantity": 1.0,
        "weight": 0.60,
        "value": 25.0
      }
    ]
  }
}

正如你所看到的,order.fields 都是参数化的,我可以为我喜欢的多次迭代获取很多不同的数据,并且我可以使用底层 API 进行动态迭代。然而,对象/项目的数组是静态的。

下面是我的数据文件示例(我刚刚粘贴了一个场景,但我有 50 个文件)

[
{        "signature_required": true,
         "reference": "Test1",
         "shipping_method":"express",
         "order_number": "{{randomOrderNumber}}",
         "order_date" : "{{$timestamp}}",
         "name" :  "Company + Building + City",
         "phone" : "00000000",
         "email": "test@test.com",
         "company": "My Company",
         "building": "My Building",
         "street": "20 Wellington Street",
         "suburb": " Bondi",
         "post_code": "2026",
         "state": "NSW",
         "city": "Sydney",
         "country": "Australia",
         "delivery_instructions": "Leave at front-door" 
},
....
....
....
]

有什么方法可以在我创建的数据文件模板中添加一个包含 1 个或多个具有不同变量的对象的数组?也许是这样的:

[
    {        "signature_required": true,
             "reference": "Test1",
             "shipping_method":"express",
             "order_number": "{{randomOrderNumber}}",
             "order_date" : "{{$timestamp}}",
             "name" :  "Company + Building + City",
             "phone" : "00000000",
             "email": "test@test.com",
             "company": "My Company",
             "building": "My Building",
             "street": "20 Wellington Street",
             "suburb": " Bondi",
             "post_code": "2026",
             "state": "NSW",
             "city": "Sydney",
             "country": "Australia",
             "delivery_instructions": "Leave at front-door" 
"items":[
 {
        "description": "My Item1",
        "sku": "Item1",
        "quantity": 1.0,
        "weight": 0.60,
        "value": 25.0
      },

 {
        "description": "My Item2",
        "sku": "Item2",
        "quantity": 1.0,
        "weight": 0.60,
        "value": 25.0
      },

]

    },
    ....
    ....
    ....
    ]

请求模板中的代码是什么?data_file.json 中的代码是什么?

4

0 回答 0