当设置为嵌套响应的全局变量时,响应数据中的Hypen会抛出错误

时间:2017-06-09 13:30:31

标签: postman

我有一个帖子man请求。它返回响应数据:

[
  {
    "id": "7ca27c09-2b67-417e-b367-f97d49824a2f",
    "tags": [],
    "type": "ApplicationProfile",
    "userId": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
    "profile": {
      "User-Profile": {
        "PHI": {
          "gender": "Male",
          "surgeryDate": {
            "value": "2017-06-06"
          },
          "surgeryType": {
            "value": "gastricBand"
          },
          "heightInches": "72",
          "approvalPhase": "2",
          "profileImageUrl": "",
          "motivationalImageUrl": ""
        },
        "PII": {
          "mail": "c11@c111.com",
          "lastName": "",
          "firstName": "name1",
          "shouldReceiveNotifications": true
        }
      },
      "motivationalGoals": [
        {
          "goal": "Improving health",
          "goalId": "2957"
        },
        {
          "goal": "Relieving pain",
          "goalId": "2958"
        },
        {
          "goal": "Feeling better",
          "goalId": "2960"
        }
      ]
    },
    "version": 35,
    "createdBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
    "lastModifiedBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
    "applicationName": "Health Partner",
    "createdDateTime": "2017-06-08T16:08:32.497Z",
    "lastModifiedDateTime": "2017-06-09T13:23:03.503Z"
  },
  {
    "id": "091b5ebd-b096-436e-a703-f97f0ae77baf",
    "tags": [
      "Application-Profile"
    ],
    "type": "ApplicationProfile",
    "userId": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
    "profile": {
      "User-Profile": {
        "PHI": {
          "gender": "",
          "surgeryDate": {
            "value": "2017-06-01"
          },
          "surgeryType": {
            "value": ""
          },
          "heightInches": "72",
          "approvalPhase": "2",
          "profileImageUrl": "",
          "motivationalImageUrl": ""
        },
        "PII": {
          "mail": "c11@c111.com",
          "lastName": "Dev",
          "firstName": "Kat",
          "shouldReceiveNotifications": true
        }
      },
      "motivationalGoals": [
        {
          "goal": "Improving health",
          "goalId": "2957"
        },
        {
          "goal": "Relieving pain",
          "goalId": "2958"
        },
        {
          "goal": "Feeling better",
          "goalId": "2960"
        }
      ]
    },
    "version": 41,
    "createdBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
    "lastModifiedBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
    "applicationName": "Health Partner Weightloss",
    "createdDateTime": "2017-06-03T16:19:57.811Z",
    "lastModifiedDateTime": "2017-06-08T16:07:49.555Z"
  }
]

我需要提取emailid的值并设置为全局变量。

这是我的代码:

var jsonData1 = JSON.parse(responseBody);
postman.setGlobalVariable("jsonData1",jsonData1.profile.User-Profile.PII.mail);

但我收到了错误。 "用户未定义"。

1 个答案:

答案 0 :(得分:0)

这里的问题是连字符/减号被解释为减法运算符。

考虑更改您的API并使用" userProfile"而不是" User-Profile"。