请找到附加的Groovy代码,我使用它从响应主体中获取特定的文件。
查询1:
当I使用正确的索引值时,它检索结果,如如果数据.RenewalDetails[o],给予输出值为1,如果数据.RenewalDetails[1],则输出值为2。
但在我的真实的情况下,我永远不会知道响应中的块数,所以我想得到所有满足条件的值,我尝试了data.RenewalDetails[*],但它不工作。你能帮忙吗?
疑问二:
除了上述条件外,我还想再添加一个筛选器,其中“FamilyCode”:在Itemdetails中有“PREMIUM”,你能帮忙吗?
def BoundId = new groovy.json.JsonSlurper().parseText('{"data":{"RenewalDetails":[{"ExpiryDetails":{"duration":"xxxxx","destination":"LHR","from":"AUH","value":2,"segments":[{"valudeid":"xxx-xx6262-xxxyyy-1111-11-11-1111"}]},"Itemdetails":[{"BoundId":"Value1","isexpired":true,"FamilyCode":"PREMIUM","availabilityDetails":[{"travelID":"AAA-AB1234-AAABBB-2022-11-10-1111","quota":"X","scale":"XXX","class":"X"}]}]},{"ExpiryDetails":{"duration":"xxxxx","destination":"LHR","from":"AUH","value":2,"segments":[{"valudeid":"xxx-xx6262-xxxyyy-1111-11-11-1111"}]},"Itemdetails":[{"BoundId":"Value2","isexpired":true,"FamilyCode":"PREMIUM","availabilityDetails":[{"travelID":"AAA-AB1234-AAABBB-2022-11-10-1111","quota":"X","scale":"XXX","class":"X"}]}]}]},"warnings":[{"code":"xxxx","detail":"xxxxxxxx","title":"xxxxxxxx"}]}')
.data.RenewalDetails[0].Itemdetails.find { itemDetail ->
itemDetail.availabilityDetails[0].travelID.length() == 33
}?.BoundId
println "Hello " + BoundId
2条答案
按热度按时间bsxbgnwa1#
大概是这样的:
请注意,您将以列表的形式获得BoundId
wgx48brx2#
1.如果您像这样修改代码:
您可以按如下方式访问返回的项目数:
因为
RenewalDetails
表示List1.只需使用Groovy的
&&
操作符添加任意多个查询即可:更多信息: