【问题标题】:How to extract the parameter from Json Response Using Groovy?如何使用 Groovy 从 Json 响应中提取参数?
【发布时间】:2013-05-16 10:31:18
【问题描述】:

以下是我的回答..

{"activation":{"existing":false, "customer": new}}

现在当我使用

testRunner.testCase.getTestStepByName("xxx").getPropertyValue("response")

以上脚本正在提取响应。现在我想提取"customer" 值。

如何做到这一点?

谢谢

【问题讨论】:

    标签: soapui


    【解决方案1】:
    import groovy.json.JsonSlurper
    
    responseContent = testRunner.testCase.getTestStepByName("xxx").getPropertyValue("response")
    slurperresponse = new JsonSlurper().parseText(responseContent)
    log.info (slurperresponse.activation.customer)
    

    【讨论】:

    • 此外,我会将activation.customer 作为动态值传递,因为这些值会随着不同的 json 响应而变化。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-09
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    • 2013-01-23
    相关资源
    最近更新 更多