当 json 对象中的键包含连字符时,可能会导致空手道出现问题。这是一个例子 -
{
"id": "1234",
"type": "FICTION",
"attribute": {
"bookPrice": "10",
"authorName": {
"firstName": "Dean",
"lastName": "Jones"
},
"links": {
"get-book-by-id": {
"href": "/v1/books/1234",
"title": "get-book-by-id"
}
}
}
}
在此示例中,键“get-book-by-id”由连字符分隔,当我尝试遍历此元素时,我收到如下错误 -
org.graalvm.polyglot.PolyglotException: ReferenceError: 'book' is not defined.
Feature: Sample
Scenario: Test1
* def response =
"""
{
"id": "1234",
"type": "FICTION",
"attribute": {
"bookPrice": "10",
"authorName": {
"firstName": "Dean",
"lastName": "Jones"
},
"links": {
"get-book-by-id": {
"href": "/v1/books/1234",
"title": "get-book-by-id"
}
}
}
}
"""
* print response.attribute.links["get-book-by-id"]