2017-09-05 65 views
1

我需要从GET请求中读取一个ID并使用POST中的ID执行测试。我从GET检索id为数组从以下表达式形式:空手道API测试 - 从JSON数组转换为字符串

And def reqId = response.teams[*].resource[1].resourceRequestId 

`["59aeb24be4b0b17227553d07"]` 

我保存这个ID作为变量:

And def reqId = response.teams[*].resource[1].resourceRequestId 

当我使用这在我POST操作,我得到以下错误:

exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Could not read document: Can not deserialize instance of java.lang.String out of START_ARRAY token\n 

有没有一种方法可以让我执行JSON.stringify()等的值转换为字符串或方法来提取,并在更加故意使用请求

回答

1

您正在发送数组而不是单个字符串。请记住,当你在JsonPath中使用[*]时,结果总是一个数组。

And def temp = response.teams[*].resource[1].resourceRequestId 
And def reqId = temp[0] 

现在尝试,它应该工作。我们正在引入一个get[0]语法便于在下一个版本中使这个更清晰。注意它。

+1

谢谢,它工作! – Saurabh