如何从JSon中提取多个相关变量

如何从JSon中提取多个相关变量,json,jmeter,json-path-expression,json-extract,Json,Jmeter,Json Path Expression,Json Extract,我必须从JMeter中的json响应中提取多个相关变量。部分答复如下: [ { "data": { "id": "efaa6876-7a8d-4723-9d85-1ed99e822f06", "type": "courses", "attributes": { "created-at": "2019-02-07T16:38:50.735Z", "contents-count": 267, "units

我必须从JMeter中的json响应中提取多个相关变量。部分答复如下:

[
  {
    "data": {
      "id": "efaa6876-7a8d-4723-9d85-1ed99e822f06",
      "type": "courses",
      "attributes": {
        "created-at": "2019-02-07T16:38:50.735Z",
        "contents-count": 267,
        "units": [
          {
            "id": "31b5fcb1-24ee-441e-a0ee-ca859fc9a89d",
            "position": null,
            "progress": 0,
            "completed": false,
            "show_name": false,
            "node_id": "1",
            "children": [
              {
                "id": "b8ed75a3-0390-4273-82c3-03ee6eba729c",
                "position": null,
                "image": null,
                "progress": 0,
                "completed": false,
                "show_name": true,
                "node_id": "2",
                "children": [],
                "contents": [
                  {
                    "id": "fa1bdc2f-4330-425c-9c10-3734d07125aa",
                    "link": {
                      "url": "#",
                      "target": "_blank",
                      "class": "learning-object-link",
                      "data": {
                        "id": "fa1bdc2f-4330-425c-9c10-3734d07125aa",
                        "user-role": "teacher",
                        "open-method-tablet": "newtab",
                        "open-method-desktop": "modal",
                        "content-open-method": null,
                        "modal-size-method": "fully_responsive",
                        "fixed-width": null,
                        "fixed-height": null,
                        "aspect-ratio": null
                      }
                    },
                    "is_work": false,
                    "is_fun": false,
                    "completed": false,
                    "total_activities": 2,
                    "completed_activities": 0,
                    "progress": 0,
                    "updated_at": false,
                    "attempts": 0,
                    "duration": null
                  },
                  {
                    "id": "ceceabfd-5151-4656-af5d-3392c5a4c04c",
                      "link": {
                      "url": "#",
                      "target": "_blank",
                      "class": "learning-object-link",
                      "data": {
                        "id": "ceceabfd-5151-4656-af5d-3392c5a4c04c",
                        "user-role": "teacher",
                        "open-method-tablet": "newtab",
                        "open-method-desktop": "modal",
                        "content-open-method": null,
                        "modal-size-method": "fully_responsive",
                        "fixed-width": null,
                        "fixed-height": null,
                        "aspect-ratio": null
                      }
                    },
                    "is_work": false,
                    "is_fun": false,
                    "completed": false,
                    "total_activities": 2,
                    "completed_activities": 0,
                    "progress": 0,
                    "updated_at": false,
                    "attempts": 0,
                    "duration": null
                  }
                ]
              },
              {
                "id": "60639cbd-f872-492d-b8e9-db83f8789fcf",
                "position": null,
                "image": null,
                "progress": 0,
                "completed": false,
                "show_name": true,
                "node_id": "3",
                "children": [],
                "contents": [
                  {
                    "id": "1825f834-7099-4bb4-b7a2-fc634faffc86",
                      "link": {
                      "url": "#",
                      "target": "_blank",
                      "class": "learning-object-link",
                      "data": {
                        "id": "1825f834-7099-4bb4-b7a2-fc634faffc86",
                        "user-role": "teacher",
                        "open-method-tablet": "newtab",
                        "open-method-desktop": "modal",
                        "content-open-method": null,
                        "modal-size-method": "fully_responsive",
                        "fixed-width": null,
                        "fixed-height": null,
                        "aspect-ratio": null
                      }
                    },
为了继续下一个请求,我必须提取装置id,例如31b5fcb1-24ee-441e-a0ee-ca859fc9a89d,儿童id,例如b8ed75a3-0390-4273-82c3-03ee6eba729c和内容id,例如fa1bdc2f-4330-425c-9c10-3734d07125aa。有几个单元,每个单元有几个子单元,每个子单元有几个内容。每个内容id只匹配一个子id,每个子id只匹配一个单元id。id必须随机选择


我尝试从响应中提取所有ID并随机使用它们,但这种方法不起作用。

要仅提取单元ID,可以使用以下JSON路径表达式:

$..data.attributes.units[?(@.id)].id
还可以使用JMeter JSON提取器提取单元Id的随机值:


我想我应该先提取单元id,然后使用这个值提取子id。当我试图提取单元id时,所有id都被提取——单元id、子id和内容id。如何只提取单元ID而不提取任何子ID?当然,请您接受这是一个答案并向上投票。我担心我的声誉太低,无法做到这一点:我收到以下消息:感谢您的反馈!声誉低于15的人所投的票将被记录,但不会改变公开显示的帖子分数。