我有一个json响应,如下所示,我只想匹配字符串“ harry”
在autoComplete中,在id中为autoCompleteAuthors
响应{“数据”:{ “自动完成”:[ “哈里·霍尔” ], “ autoCompleteAuthors”:[ { “ id”:“ search_authors_harry martinson”, “ title”:“ Harry Martinson”, “ type”:“作者” } ] } }
请建议如何使用包含来执行此验证?
我尝试了以下操作 * def autoComlete =获取response.data.autoComplete [*] * match autoComlete包含任何“ harry”
答案 0 :(得分:1)
您可以在空手道中使用match each
和#regex
标记,
区分大小写的匹配
* match each $response.data.autoComplete == "#regex .*Harry.*"
区分大小写
* match each $response.data.autoComplete == "#regex (?i).*harry.*"
希望这可以满足您的需求。
编辑: 根据评论要求传递姓名
* def query = 'harry'
* match each $response.data.autoComplete == "#regex (?i).*" + query + ".*"