gpt4 book ai didi

java - 如何放心地将数组插入到 JSONArray 中

转载 作者:太空宇宙 更新时间:2023-11-04 09:50:02 24 4
gpt4 key购买 nike

我想放心地插入数组。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");
}

最佳答案

尝试单独添加每个 token

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

关于java - 如何放心地将数组插入到 JSONArray 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54902841/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com