RestAssured JsonPath:从 json 获取数据时出现问题

RestAssured JsonPath: Issue with getting data from json

我需要从 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")

对我来说 returns 周的所有列表。

我发现得到我需要的唯一方法就是这样

getJsonPath().getList("years[1]['2017'].weeks.find{it.isoWeekNum == '1'}")

但这不是我要找的。我需要找到一个解决方案,我可以在没有 2017 年 [1] 年和 2016 年 [0] 年

的情况下获取数据
 "{
  "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": []
          }
        ]
      }
    }
  ]
}

希望以下代码正是您要查找的内容:

public static void main(final String[] args) {
    JsonPath jsonPath = new JsonPath(yourJson).using(new JsonPathConfig("UTF-8"));

    System.out.println(
            jsonPath.get("years['2017'].weeks*.find {it.isoWeekNum == '1'}")
    );
}