RestAssured JsonPath:从json获取数据的问题

时间:2016-12-08 05:17:30

标签: java rest-assured rest-assured-jsonpath

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

但这不是我想要的。我需要找到一个解决方案,我可以在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": []
          }
        ]
      }
    }
  ]
}

0 个答案:

没有答案