定义一个变量来设置数组的长度失败但断言和打印有效

defining a variable to set length of an array is failing but assert and print works

com.jayway.jsonpath.PathNotFoundException: Expected to find an object with property ['length'] in path $['teams'][0]['teamMembers'] but found 'net.minidev.json.JSONArray'.
This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.

非常感谢任何帮助。

是的,空手道假定右侧为 Json-路径(这对 90% 的情况都适用)。在需要时使用括号强制 JavaScript 求值。

试试这个:

def count = (response.teams[0].teamMembers.length)

详细解释请参考文档中的这一段:Karate Expressions