简体   繁体   English

使用基于以下 JSON 的 Rest Assured 的 2x 数组 POST 请求

[英]2x array POST request using Rest Assured based on the following JSON

please help me to create the body request from the following output:请帮助我从以下输出创建正文请求:

{
  "categoryIds": [
    [
      "4654-456465-4564",
      "4654-456465-9512"
    ]
  ],
  "lastUpdate": "1231",
  "controlStructureId": "4654-456465-4564",
  "controntrolId": "4654-456465-4564",
  "vehicleId": "4654-456465-4564"
}

My code:我的代码:

 Map<String,Object> jsonBodyUsingMap = new HashMap<String,Object>();
        jsonBodyUsingMap.put("lastUpdate", "1231");
        jsonBodyUsingMap.put("controlStructureId", "4654-456465-4564");
        jsonBodyUsingMap.put("controntrolId", "4654-456465-4564");
        jsonBodyUsingMap.put("vehicleId", "4654-456465-4564");

But I have no idea with categoryIds , please help但我不知道categoryIds ,请帮忙

This will solve your problem.这将解决您的问题。 So just put as ArrayList within another ArrayList and it'll be converted to an array by whatever JSON converter you're using:因此,只需将 ArrayList 放在另一个 ArrayList 中,它就会被您使用的任何 JSON 转换器转换为数组:

    Map<String,Object> jsonBodyUsingMap = new HashMap<String,Object>();
    jsonBodyUsingMap.put("lastUpdate", "1231");
    jsonBodyUsingMap.put("controlStructureId", "4654-456465-4564");
    jsonBodyUsingMap.put("controntrolId", "4654-456465-4564");
    jsonBodyUsingMap.put("vehicleId", "4654-456465-4564");

    List<Object> categories = new ArrayList<>();
    List<String> subcategories = new ArrayList<>();
    subcategories.add("4654-456465-4564");
    subcategories.add("4654-456465-9512");
    categories.add(subcategories);
    jsonBodyUsingMap.put("categoryIds", categories);

The result of this will be:这样做的结果将是:

{
   "categoryIds":[
      [
         "4654-456465-4564",
         "4654-456465-9512"
      ]
   ],
   "controlStructureId":"4654-456465-4564",
   "controntrolId":"4654-456465-4564",
   "lastUpdate":"1231",
   "vehicleId":"4654-456465-4564"
}

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

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