尝试匹配空手道框架中 API 响应中的嵌套 json 对象。
以下是我的 API 响应。
"status": {
"code": 0,
"message": "Successful"
},
"data": {
"PHX": {
"name": "Phoenix (All)",
"city_code": "PHX",
"country_code": "US",
"country_name": "United States",
"city_name": "Phoenix",
"type": "city",
"airports": {
"SCF": {
"name": "Scottsdale Municipalcipal",
"city_code": "PHX",
"city_name": "Phoenix",
"country_code": "US",
"country_name": "United States",
"lat": 33.61667,
"lng": -111.916664,
"timezone": "America/Phoenix",
"type": "airport"
},
"PHX": {
"name": "Sky Harbor International",
"city_code": "PHX",
"city_name": "Phoenix",
"country_code": "US",
"country_name": "United States",
"lat": 33.435036,
"lng": -112.00016,
"timezone": "America/Phoenix",
"type": "airport"
},
"AZA": {
"name": "Williams Gateway",
"city_code": "PHX",
"city_name": "Phoenix",
"country_code": "US",
"country_name": "United States",
"lat": 33.307777,
"lng": -111.655556,
"timezone": "America/Phoenix",
"type": "airport"
},
"DVT": {
"name": "Phoenix Deer Valley Airport",
"city_code": "PHX",
"city_name": "Phoenix",
"country_code": "US",
"country_name": "United States",
"lat": 33.683887,
"lng": -112.083336,
"timezone": "America/Phoenix",
"type": "airport"
},
"LUF": {
"name": "Luke AFB",
"city_code": "PHX",
"city_name": "Phoenix",
"country_code": "US",
"country_name": "United States",
"lat": 33.61667,
"lng": -111.916664,
"timezone": "America/Phoenix",
"type": "airport"
}
}
}
}
}
我正在尝试匹配 json 对象data,这里非常棘手的部分是关键“PHX”将是动态的,我可能会得到尽可能多的 json 嵌套对象。还有airports像“SCF”、“PHX”、“AZA”这样的嵌套 json 也是动态的。如何在空手道中写比赛语句?
尝试了动态密钥的几个答案,但我的 API 响应在这里完全不同。
我尝试了以下功能文件的更改:
* def response_data_airports = { "#string": { "name": "#string", "city_code": "#string", "city_name": "#string", "country_code": "#string", "country_name": "#string", "lat": "#number", "lng": "#number", "timezone": "#string", "type": "#string" }}
* def main_schema = { '#string': { "name": "#string", "city_code":
"#string", "country_code": "#string", "country_name": "#string",
"city_name": "#string", "type": "#string", "airports":
'#(^response_data_airports)' } }
* match flightAutocompleteDetails.response.data contains main_schema
谢谢