英文:
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')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论