ReadyApi属性传输计算JSON数组响应中的元素数量

huangapple go评论83阅读模式
英文:

ReadyApi Property Transfer counting elements in JSON array response

问题

在“Transfer Property”页面上,如何设置一个包含 JSON 数组响应中元素数量的属性?

例如:

JSON 响应:
[
{
"category": "XXX",
"other": "YYY",
"another": "ZZZ"
},
{
"category": "XXX",
"other": "YYY",
"another": "ZZZ"
}
]

我正在使用 JSON Path,并且有以下表达式:
$[?(@.category == 'XXX')].length()

属性应设置为 2。

英文:

On the Transfer Property page, how do I set a property which contains the count of the number of elements in a JSON array response?

e.g.

JSON response:
[
{
"category": "XXX",
"other": "YYY",
"another": "ZZZ"
},
{
"category": "XXX",
"other": "YYY" ,
"another": "ZZZ"
}
]

I am using JSON Path,
and have an expression as follows:
$[?(@.category == 'XXX')].length()

property -> [[3, 3]]

I require a count property to be set to 2.

答案1

得分: 0

JSONPath对任何函数的支持都非常有限,特别是在ReadyAPI/SoapUI中。

您可以使用属性:ResponseAsXml,并使用XPath的count()函数。因此,表达式可能会是count(//category='XXX')

英文:

JSONPath has very sketchy support for any functions, certainly in ReadyAPI/SoapUI.

You could use Property: ResponseAsXml, and use the XPath count() function. So the expression will likely be count(//category='XXX')

huangapple
  • 本文由 发表于 2023年7月11日 02:36:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76656434.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定