问题描述
我正在尝试访问从两 (2) 个图形 API 调用中收到的 JSON 输出中的值,但每次尝试使用它们时,我都会收到此错误:
表达评估失败。模板操作'For_each' 的执行失败:'foreach' 表达式'@body('Parse_JSON_-_Managed_Devices')?['body']?['value']' 的评估结果是'Null' 类型。结果必须是一个有效的数组。
我已验证我的图形 API 调用格式正确,并且输出正是我期望从两个 API 调用返回的内容。每次尝试访问 Azure Runbook 中解析的 JSON 或任何其他逻辑应用任务时,我都会收到此错误。
我很想知道是否有人以前遇到过这种情况以及如何解决?
图形查询: https://graph.microsoft.com/beta/deviceManagement/managedDevices/?$select=id,emailAddress&$filter=operatingSystem eq 'windows'
受管设备的 JSON 架构
{
"properties": {
"body": {
"properties": {
"@@odata.context": {
"type": "string"
},"@@odata.count": {
"type": "integer"
},"@@odata.nextLink": {
"type": "string"
},"value": {
"items": {
"properties": {
"azureADdeviceid": {
"type": "string"
},"deviceName": {
"type": "string"
},"emailAddress": {
"type": "string"
},"id": {
"type": "string"
},"managedDeviceName": {
"type": "string"
},"userdisplayName": {
"type": "string"
},"userId": {
"type": "string"
}
},"required": [
"id","userId","deviceName","userdisplayName","azureADdeviceid","managedDeviceName","emailAddress"
],"type": "object"
},"type": "array"
}
},"type": "object"
}
},"type": "object"
}
图形查询: https://graph.microsoft.com/beta/users?$select=id,officeLocation&$filter=accountEnabled eq true
用于用户的 JSON 架构 图查询:displayName": { "type": "string" },"mail": { "type": "string" },"officeLocation": { "type": "string" } },"displayName","mail","officeLocation" ],"type": "object"
}
解决方法
我认为您的架构不应包含 body
。这是我根据响应正文生成的架构。
{
"properties": {
"@@odata.context": {
"type": "string"
},"@@odata.nextLink": {
"type": "string"
},"value": {
"items": {
"properties": {
"displayName": {
"type": "string"
},"id": {
"type": "string"
},"mail": {
"type": "string"
},"officeLocation": {}
},"required": [
"id","displayName","mail","officeLocation"
],"type": "object"
},"type": "array"
}
},"type": "object"
}
那你可以试试用这个表达:
body('Parse_JSON_-_Managed_Devices')?['value']