【发布时间】:2016-12-08 05:17:29
【问题描述】:
我需要从结构怪异的 json 文件中获取数据,但我找不到解决方案。我正在使用带有 jsonPath 的 restAssured 当我试图像这样获取特定一周的数据时
getJsonPath().getList("years.2017.weeks.find{it.isoWeekNum == '1'}")
我遇到了一个错误
Invalid JSON expression: Script1.groovy: 1: unexpected token: 2017 @ line 1, column 33.
years.2017.weeks.find{it.isoWeekNum == '1'}
同时我可以用这个表达式获取数据
getJsonPath().getList("years.2017.weeks")
返回给我的所有周列表。
我发现得到我需要的唯一方法就是这样
getJsonPath().getList("years[1]['2017'].weeks.find{it.isoWeekNum == '1'}")
但这不是我要找的。我需要找到一个解决方案,我可以在没有年份 [1] 的 2017 年和年份 [0] 的 2016 年获取数据
"{
"years": [
{
"2016": {
"currentIsoWeek": "49",
"currentTourWeek": "49",
"weeks": [
{
"isoWeekNum": "1",
"tourWeekNum": "1",
"categories": []
},
{
"isoWeekNum": "2",
"tourWeekNum": "2",
"categories": []
}
]
}
},
{
"2017": {
"currentIsoWeek": "",
"currentTourWeek": "",
"weeks": [
{
"isoWeekNum": "1",
"tourWeekNum": "1",
"categories": []
},
{
"isoWeekNum": "2",
"tourWeekNum": "2",
"categories": []
}
]
}
}
]
}
【问题讨论】:
标签: java rest-assured rest-assured-jsonpath