在空手道中使用set关键字,错误为“字符串索引超出范围:-1”

时间:2018-12-20 05:16:54

标签: karate

下面是我遇到错误的代码段。

* def json = {"test" : { "data.a":'value',"data.b":'value2' }}
* print json.test["data.a"] // This line is working getting value 'value'
* set json.tes["data.a"] = 'hello' // This line is failing with error "String index out of range: -1

Response:
 [java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:1967)
    at com.intuit.karate.JsonUtils.setValueByPath(JsonUtils.java:257)
    at com.intuit.karate.Script.setValueByPath(Script.java:1519)
    at com.intuit.karate.Script.setValueByPath(Script.java:1489)
    at com.intuit.karate.Script.setValueByPath(Script.java:1479)
    at com.intuit.karate.StepDefs.setNamedByPath(StepDefs.java:572)
    at com.intuit.karate.StepDefs.setByPath(StepDefs.java:562)
    at ✽.* set json.tes["data.a"] = 'hello' // This line is failing with error "String index out of range: -1

无法使用SET关键字动态设置“ data.a”的值。 请帮忙。

1 个答案:

答案 0 :(得分:2)

这似乎是设计错误的JSON。进行一些小的更改,请使用eval

* eval json.test["data.a"] = 'hello'