Powershell ServiceNow em_事件表附加_信息字段正在返回[object object]
我们通过PowerShell(调用RestMethod)使用RESTAPI,以便使用web服务API通过单个调用在ServiceNow事件[em_event]表中插入记录 我们成功地将事件插入em_事件表, 但唯一的问题是附加信息字段 出于某种原因 我的PowerShell脚本的JSON结构, 正在导致附加信息的输出作为对象而不是JSON字符串返回 因此,, 附加信息中的值未正确显示,而是显示为[object]: 这是我的PowerShell脚本中的JSON结构:Powershell ServiceNow em_事件表附加_信息字段正在返回[object object],powershell,rest,servicenow,Powershell,Rest,Servicenow,我们通过PowerShell(调用RestMethod)使用RESTAPI,以便使用web服务API通过单个调用在ServiceNow事件[em_event]表中插入记录 我们成功地将事件插入em_事件表, 但唯一的问题是附加信息字段 出于某种原因 我的PowerShell脚本的JSON结构, 正在导致附加信息的输出作为对象而不是JSON字符串返回 因此,, 附加信息中的值未正确显示,而是显示为[object]: 这是我的PowerShell脚本中的JSON结构: # Specify requ
# Specify request body
$body = @"
{ "records":
[
{
"source":"MyClass",
"event_class":"$AtargetResourceType",
"resource":"$AtargetResourceType",
"node":"$AtargetResourceName",
"metric_name":"$Aname",
"type":"$AsignalType",
"severity":"$Aseverity",
"message_key":"$Aid",
"u_mc_object":"$AtargetResource",
"description":"$Adescription",
"additional_info":"{
'u_mc_object_class':'$AsourceCreatedId',
'u_mc_parameter':'$AmetricName',
'u_mc_parameter_value':'$AmetricValue'
}"
}
]
}
"@
您发布的图像未打开。但根据您的问题,以下行将返回字符串值以获取其他信息:
($body|ConvertFrom-Json).records.additional_info
我使用邮递员发送请求时遇到了同样的问题,我发送请求时是这样的:
{ "records":
[
{
"source":"BMC TrueSight",
"type":"Incident from trusight",
"severity":"1",
"description":"This is a test from WEB SERVICE API ERROR",
"additional_info":{
"status":"new",
"description":"This is a descriotion from additional information",
"category":"41",
"subcategory": "test",
"company": "test",
"business_service":"test"
}
}
]
}
"additional_info": "{\"assignee_group\":\"ETSS\/UNIX99\",\"status\":\"new\",\"description\":\"This is a descriotion from additional information\",\"category\":\"41\",\"subcategory\":\"test\",\"company\":\"test\",\"business_service\":\"
}
它在附加信息字段中显示[object][object],我所做的是将该字段作为如下字符串发送:
{ "records":
[
{
"source":"BMC TrueSight",
"type":"Incident from trusight",
"severity":"1",
"description":"This is a test from WEB SERVICE API ERROR",
"additional_info":{
"status":"new",
"description":"This is a descriotion from additional information",
"category":"41",
"subcategory": "test",
"company": "test",
"business_service":"test"
}
}
]
}
"additional_info": "{\"assignee_group\":\"ETSS\/UNIX99\",\"status\":\"new\",\"description\":\"This is a descriotion from additional information\",\"category\":\"41\",\"subcategory\":\"test\",\"company\":\"test\",\"business_service\":\"
}
您只需要将JSON转换为字符串。您能详细说明您的答案吗?在JSON结构中,我需要在哪里使用这一行?我需要使用converttojson吗?(cmdlet将任何对象转换为JavaScript对象表示法(JSON)格式的字符串)