没有这样的财产:它适合上课

时间:2017-01-19 15:24:55

标签: groovy soapui

我正在尝试检索'搜索'的所有实例的列表。从json响应并设置它,以便任何包含' null'更改为0.但是我收到错误说明no such property: it for class.我如何解决此问题以确保我的代码正常工作,因此任何' null'改为0?

import groovy.json.JsonSlurper 
    def response = messageExchange.response.responseContent
    def json =  new JsonSlurper().parseText(response)


    def resultItems = json.xxx.xxx.items
    def resultSearchCostGroup = json.xxx.xxx.xxx.search
    int totalSearchCostGroup = resultSearchCostGroup.flatten().collect(it ?:0 ).sum() 

1 个答案:

答案 0 :(得分:0)

你的最后一行应该是

int totalSearchCostGroup = resultSearchCostGroup.flatten().collect { it ?:0 }.sum()