![](/img/trans.png)
[英]How do I turn JSON into plain old data (Map, List, String, Int etc.) in Scala/Play
[英]In Karate DSL, how can I use the replace text for other data types such as int, float, Big, etc.?
我在github上找到了以下示例。
def text ='你好世界再见'
替换文字| 令牌| 价值| | 一| “残酷” | | 二| '好'|
匹配文字=='你好残酷的世界再见'
如果我要替换的值只能接受整数或其他数据类型怎么办? 例如,
我无法将令牌放入另一个文件中,因为json验证程序不喜欢<>没有双引号的情况。 有什么建议么?
替换用于文本而非JSON,请仔细阅读文档。 首先,数字和替换没有问题:
* def text = 'hello <name> how many <hours>'
* replace text
| token | value |
| name | 'John' |
| hours | 200 |
* match text == 'hello John how many 200'
现在,如果您尝试摆弄JSON,只需使用set
关键字。
* def json = { hello: '', hours: null }
* set json
| path | value |
| hello | 'John' |
| hours | 200 |
* match json == { hello: 'John', hours: 200 }
请注意,即使您省略第一行,上述内容也可以使用。 另请参阅嵌入式表达式,作为在JSON中替换值的另一种方法,请参考文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.