简体   繁体   English

在soapui中使用groovy计数JSON响应的子节点

[英]Count child nodes of a JSON response using groovy in soapui

I have a JSON response due to security reasons I had to take a screenshot and post it here. 由于安全原因,我有一个JSON响应,因此我不得不截取屏幕截图并将其发布在此处。

在此处输入图片说明

I need to find number of available itineraryPrice available. 我需要找到可用的行程价格。 Each curly braces refers to a separate itinerary, how to I count those tags in a groovy script step. 每个花括号都指向一个单独的行程,如何在常规脚本步骤中计算这些标记。

Method I have tried 我尝试过的方法

def holder = groovyUtils.getXmlHolder( "air-search#ResponseAsXml" )
def xpath = "//*:search/*:itineraryPrice"
def numberOfRecommendations = holder["count(//*:search/*:itineraryPrice)"]
log.info "Total no of recommendations : "+numberOfRecommendations

But I got the output as 1 :( 但我得到的输出为1 :(

Kindly help ! 请帮助! Please refer screenshot as well. 请同时参考屏幕截图。

def json = '''{
"pos":"...",
"search":{
  "uri":"...",
  "itineraryPrice":[
    {"a":1},
    {"a":22},
    {"a":333},
    {"a":4},
    {"a":56}
  ]
}
}'''

json = new groovy.json.JsonSlurper().parseText(json)
def count = json.search.itineraryPrice.size()

output: 5 输出: 5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM