简体   繁体   English

在字符串的 Json 数组中,如何匹配存在的字符串的一部分? 空手道DSL

[英]In Json array of strings, how can I match a part of string is present? Karate DSL

I have a Json array of strings as below.我有一个 Json 字符串数组,如下所示。

How can I validate whether it contains today's date 2021-10-11 or the word PROCESSING-1 as a sub string in it?如何验证它是否包含今天的日期2021-10-11或单词PROCESSING-1作为其中的子字符串? BTW, I am trying it with Karate DSL顺便说一句,我正在尝试使用空手道 DSL

[
  "TEST1019005-2021-10-19T18:19:41.271055Z-PROCESSING-2",
  "TEST1019005-2021-10-19T18:19:41.271055Z-PROCESSING-1",
  "TEST1019002-2021-10-19T14:50:16.810678Z-PROCESSING-2",
  "TEST1019002-2021-10-19T14:50:16.810678Z-PROCESSING-1",
  "TEST1019002-2021-10-19T14:50:16.810678Z-PROCESSING-0",
  "777777-2021-10-19T09:24:33.064845Z-PROCESSING-2",
  "777777-2021-10-19T08:23:10.213230Z-PROCESSING-1",
  "777777-2021-10-19T08:23:10.213230Z-PROCESSING-0",
  "TEST1018001-2021-10-18T16:31:32.643392Z-PROCESSING-0",
  "TEST1013001-2021-10-13T15:13:59.974540Z-PROCESSING-0",
  "777777-2021-10-13T14:17:45.727585Z-PROCESSING-2",
  "Test01-2021-10-11T20:20:05.968159Z-PROCESSING-1",
  "Test01-2021-10-11T20:20:05.968159Z-PROCESSING-0",
  "333333333-2021-10-11T20:11:26.474697Z-PROCESSING-0",
  "333333333-2021-10-08T21:43:28.251925Z-PROCESSING-0",
  "232623234-2021-10-08T21:27:04.363014Z-PROCESSING-0",
]

Here's part of the solution:这是解决方案的一部分:

* def today = 
"""
function() {
  var Formatter = Java.type("java.time.format.DateTimeFormatter");
  var LocalDate = Java.type("java.time.LocalDate");  
  var dtf = Formatter.ofPattern("yyyy-MM-dd");
  return dtf.format(LocalDate.now());
}
"""
* match each response contains today()

The rest is up to you.剩下的就看你了。 Note that there is a #regex match option as well: https://github.com/karatelabs/karate#fuzzy-matching请注意,还有一个#regex匹配选项: https : //github.com/karatelabs/karate#fuzzy-matching

Also refer these answers: https://stackoverflow.com/a/60945563/143475另请参阅这些答案: https : //stackoverflow.com/a/60945563/143475

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

相关问题 如何在空手道中将 Json Object 转换为 Json 数组? - How can I convert to Json Object to Json Array in Karate? 空手道 DSL - 如何从 __arg 读取令牌字符串并在 json 请求中发送此字符串? - Karate DSL - How to read token string from __arg and send this string in json request? 在空手道DSL中,如何将替换文本用于其他数据类型,例如int,float,Big等? - In Karate DSL, how can I use the replace text for other data types such as int, float, Big, etc.? 如何在不进行双重编码的情况下从json字符串数组创建json字符串? - How can I create a json string from an array of json strings without double encoding? 在C#中,当一个字段可能是字符串或字符串数​​组时,如何反序列化此json? - In C# how can I deserialize this json when one field might be a string or an array of strings? 如何匹配JSON数组中的字符串? - how to match string in JSON array? 如何在空手道中针对预定义的json模式验证响应? - how can I verify response against a predefined json schema in karate? 如何在空手道中将变量用作 json 键? - How can I use a variable as a json key in karate? 如何在 Swift 中加粗来自 JSON 的字符串的一部分? - How can I bold part of a string from JSON in Swift? 如何获取json字符串某些部分的值? - How can I get the values of some part of a json string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM