如果json字段具有特殊字符作为点,则访问json字段值 [英] access a json field value if the json field has special chars as dots
本文介绍了如果json字段具有特殊字符作为点,则访问json字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的json文件的字段具有特殊字符(以我的情况为点),那么如何在空手道中访问字段值?
If I have a json file with fields having special chars (in my case dots) how can I access the field value in Karate?
例如,具有一个名为example.json的json文件
For example having a json file called example.json
{
"field1" : {
"field2" : "value2",
"field.3" : "value3"
}
}
如果我想获取"field.3"字段的值怎么办?
if I want to get the value of "field.3" field how can do?
Scenario: read a json file
* def myJson = read("example.json")
* match myJson.field1.field2 == "value2"
* match myJson.field1.field.3 == "value3" # this fails
* match myJson.field1."field.3" == "value3" # this fails
* match myJson.field1.'field.3' == "value3" # this fails
* match myJson.field1.'field\.3' == "value3" # this fails
推荐答案
使用方括号:
* myJson.field1['field.3']
这篇关于如果json字段具有特殊字符作为点,则访问json字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文