如何放心将数组插入JSONArray

时间:2019-02-27 10:05:26

标签: java rest-assured

我要插入带有“确保放心”的数组。 tokenUUIDs-是一个数组(我在上一步中定义的变量)。 当我运行代码时-tokenUUIDs收到了正确的值,但是ArraytokenUUIDs没有收到好的结果。他收到了:[[Ljava.lang.String;@6fc0bbc6]

这是我的方法

public static void releaseTokens(String[] tokenUUIDs )
{
    try{
        RequestSpecification request = RestAssured.given();
        request.header("Content-Type", "application/json");

        JSONObject releaseTokens = new JSONObject();
        releaseTokens.put("partnerCode", commonOps.partnerCode);
        releaseTokens.put("apiAccessToken",commonOps.openAccessToken);
        releaseTokens.put("sessionUUID",SessionUUID);
        releaseTokens.put("taskUUID","TaskUUID");

        JSONArray ArraytokenUUIDs = new JSONArray();
        ArraytokenUUIDs.add(tokenUUIDs);


        releaseTokens.put("tokenUUIDs", ArraytokenUUIDs);


        request.body(releaseTokens.toJSONString());

        Response response = request.post((getData("APIenv") + "/api/sessions/releaseTokens.php"));
        int code = response.getStatusCode();

        Assert.assertEquals(code, 200);

        System.out.println("Status code for releaseTokens.php is" +code );

        ResponseBody bodyreleaseTokens = response.getBody();
        System.out.println("Body bodyreleaseTokens.php  " + bodyreleaseTokens.asString() );
        String statusbodyreleaseTokens = bodyreleaseTokens.asString();

        String status = response.getBody().jsonPath().getString("status");
        Assert.assertEquals(status, "OK");




        test.log(LogStatus.PASS, "bodyreleaseTokens is done" );
    }

    catch (Exception e)
    {

        test.log(LogStatus.FAIL, "bodyreleaseTokens is not done");
        test.log(LogStatus.FAIL, e.getMessage());
        fail ("bodyreleaseTokens is not done");
    }

2 个答案:

答案 0 :(得分:0)

更改

ArraytokenUUIDs.add(tokenUUIDs);

for (String tokenUUID : tokenUUIDs) {
    ArraytokenUUIDs.add(tokenUUID);
}

还要考虑将Java中的变量以小写首字母命名作为标准,以避免与类混淆。

答案 1 :(得分:0)

尝试单独添加每个令牌

  for (String s : tokenUUIDs){
      ArraytokenUUIDs.add(s);
   }