Postman 当设置为嵌套响应的全局变量时,响应数据中的Hypen抛出错误
我有一个邮差的要求。它返回响应数据,如下所示:Postman 当设置为嵌套响应的全局变量时,响应数据中的Hypen抛出错误,postman,Postman,我有一个邮差的要求。它返回响应数据,如下所示: [ { "id": "7ca27c09-2b67-417e-b367-f97d49824a2f", "tags": [], "type": "ApplicationProfile", "userId": "2f2c8684-874d-49ea-bfa4-977069c1e3e2", "profile": { "User-Profile": { "PHI": {
[
{
"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);
但是我犯了一个错误。“用户未定义”。这里的问题是连字符/减号被解释为减法运算符
考虑更改API并使用“用户配置文件”而不是“用户配置文件”。这是否回答了您的问题?这是一个JavaScript问题,而不是邮递员问题。