如果 json 字段具有特殊字符作为点,则访问 json 字段值

access a json field value if the json field has special chars as dots

如果我有一个 json 文件,其中的字段具有特殊字符(在我的例子中是点),我如何访问空手道中的字段值?

例如,有一个名为 example.json

的 json 文件
{
  "field1" : {
      "field2" : "value2",
      "field.3" : "value3"
  }
}

如果我想得到"field.3"字段的值怎么办?

  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']