响应:
[
{
"salesChannelName": "Global Customers",
"customerSegmentName": "Top Global Customers",
"productSolutionName": "Network Solutions",
"topology": "",EDIT:
"productFamilyName": "Wavelengths",
"customerScenarioName": "",
"productQuestionId": "1"
}
]
编辑:基于OP评论
我正在尝试检查'salesChannelName'是否正在返回字母或不使用groovy脚本。
答案 0 :(得分:1)
在这里,请按行注释。
脚本
import groovy.json.JsonSlurper
def jsonString = """[
{
"salesChannelName": "Global Customers",
"customerSegmentName": "Top Global Customers",
"productSolutionName": "Network Solutions",
"topology": "",
"productFamilyName": "Wavelengths",
"customerScenarioName": "",
"productQuestionId": "1"
}
]"""
//Regular expression to check the data is characters
def pattern = "[a-z,A-Z,' ']+"
def json = new JsonSlurper().parseText(jsonString)
//Get the sales channel name
println json[0].salesChannelName
//verify
assert json[0].salesChannelName =~ pattern