简体   繁体   English

soap ui使用groovy脚本从json响应中检索值

[英]soap ui retrieving value from json response using groovy script

how can i get the sample id of a product for which status is 'available' from the json response using groovy script 我如何使用groovy脚本从json响应中获取状态为“可用”的产品的样品ID
[ { "sampleId": "17", "partNumber": "83729219", "sampleName": "Peter", "shortDescription": "Peter", "description": "Peter", "productUrl": " https://www.alwaysdis ", "sampleImage": " http://sit1.author.gillette ", "sku": null, "categoryId": 4, "parentSampleId": null, "locale": "en-GB", "variantName": "Pads Plus", "stockCount": 0, "noOfOrderPerCategory": 0, "noOfOrderPerSample": 0, "status": "NOT_AVAILABLE", "variants": [] }, { "sampleId": "27", "partNumber": "83729568", "sampleName": "ALWAYS DISCREET Incontinence Pants Normal", "shortDescription": null, "description": "\\n [{“ sampleId”:“ 17”,“ partNumber”:“ 83729219”,“ sampleName”:“ Peter”,“ shortDescription”:“ Peter”,“ description”:“ Peter”,“ productUrl”:“ https:/ /www.alwaysdis “,” sampleImage“:” http://sit1.author.gillette “,” sku“:null,” categoryId“:4,4,” parentSampleId“:null,” locale“:” en-GB“, “ variantName”:“ Pads Plus”,“ stockCount”:0,“ noOfOrderPerCategory”:0,“ noOfOrderPerSample”:0,“ status”:“ NOT_AVAILABLE”,“ variants”:[]},{“ sampleId”:“ 27 “,” partNumber“:” 83729568“,” sampleName“:”总是禁止失禁裤正常“,” shortDescription“:null,” description“:” \\ n

  • ALWAYS DISCREET Incontinence Pants for sensitive bladder. 始终禁用敏感尿失禁裤。 RapidDry an", "productUrl": " https://www.alwainence-pants/always-discreet-medium-incontinence-pants ", "sampleImage": "/sitecore/media library/AlwaysDiscreet_UK/Im", "sku": null, "categoryId": 4, "parentSampleId": null, "locale": "en-GB", "variantName": " ", "stockCount": 79, "noOfOrderPerCategory": 0, "noOfOrderPerSample": 0, "status": "AVAILABLE", "variants": [] } ] RapidDry an“,” productUrl“:” https://www.alwainence-pants/always-discreet-medium-incontinence-pants “,” sampleImage“:” / sitecore / media library / AlwaysDiscreet_UK / Im“,” sku“: null,“ categoryId”:4,“ parentSampleId”:null,“ locale”:“ en-GB”,“ variantName”:“”,“ stockCount”:79,“ noOfOrderPerCategory”:0,“ noOfOrderPerSample”:0,“状态”:“可用”,“变体”:[]}]

    how can i get the sample id of a product for which status is 'available' from the json response using groovy script. 我如何使用groovy脚本从json响应中获取状态为“可用”的产品的样品ID。

  • You can use JSONSlurper to parse the String and then just use a Closure to filter the data, like this: 您可以使用JSONSlurper解析String,然后仅使用Closure过滤数据,如下所示:

    def slurper = new groovy.json.JsonSlurper()
    def result = slurper.parseText(jsonData)
    def availableSamples = result.findAll{it.status == 'AVAILABLE'}
    

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

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