gpt4 book ai didi

azure - 逻辑应用无法从解析 JSON 操作中找到值

转载 作者:行者123 更新时间:2023-12-03 05:01:29 35 4
gpt4 key购买 nike

我有一个由 HTTP 调用触发的逻辑应用。此调用会带来一组 header ,其中大多数在不同的 switch 语句中使用。使用解析 JSON 操作,我从请求中输入 header ,它们成功解析(图 1),但对于其中一个 header (searchType),switch 语句由于某种原因计算为 null(图 2)。 我一生都无法弄清楚为什么。

我尝试从头开始重新制作逻辑应用程序,将应用程序完全复制到不同的环境,并尝试使用表达式来访问解析的值而不是动态内容。当我尝试该表达式时,我被告知这是一个无效表达式(图 3)。该表达式是代码 View 中使用的表达式的直接副本。

有什么建议可以解决这个问题吗?

Successful parsing of headers

enter image description here

parsed header evaluates to null

enter image description here

expression invalid

enter image description here

用于复制逻辑应用的 JSON

{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"HeadersJson": {
"inputs": {
"content": "@triggerOutputs()['headers']",
"schema": {
"properties": {
"APICallFor": {
"type": "string"
},
"Accept-Encoding": {
"type": "string"
},
"Accept-Language": {
"type": "string"
},
"Connection": {
"type": "string"
},
"Content-Length": {
"type": "string"
},
"Content-Type": {
"type": "string"
},
"Host": {
"type": "string"
},
"User-Agent": {
"type": "string"
},
"searchType": {
"type": "string"
},
"x-ms-action-tracking-id": {
"type": "string"
},
"x-ms-activity-vector": {
"type": "string"
},
"x-ms-client-request-id": {
"type": "string"
},
"x-ms-client-tracking-id": {
"type": "string"
},
"x-ms-correlation-id": {
"type": "string"
},
"x-ms-execution-location": {
"type": "string"
},
"x-ms-tracking-id": {
"type": "string"
},
"x-ms-workflow-id": {
"type": "string"
},
"x-ms-workflow-name": {
"type": "string"
},
"x-ms-workflow-operation-name": {
"type": "string"
},
"x-ms-workflow-resourcegroup-name": {
"type": "string"
},
"x-ms-workflow-run-id": {
"type": "string"
},
"x-ms-workflow-run-tracking-id": {
"type": "string"
},
"x-ms-workflow-subscription-id": {
"type": "string"
},
"x-ms-workflow-system-id": {
"type": "string"
},
"x-ms-workflow-version": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {},
"type": "ParseJson"
},
"Switch": {
"cases": {
"Get_Departments": {
"actions": {
"Switch_3": {
"cases": {
"Case": {
"actions": {
"Response_5": {
"inputs": {
"body": "got to individual",
"statusCode": 200
},
"kind": "Http",
"runAfter": {},
"type": "Response"
}
},
"case": "individual"
},
"Case_2": {
"actions": {
"Response": {
"inputs": {
"body": "got to bulk",
"statusCode": 200
},
"kind": "Http",
"runAfter": {},
"type": "Response"
}
},
"case": "bulk"
}
},
"default": {
"actions": {
"Response_3": {
"inputs": {
"body": "the searchType parameter is not valid",
"statusCode": 200
},
"kind": "Http",
"runAfter": {},
"type": "Response"
}
}
},
"expression": "@body('HeadersJson')?['serachType']",
"runAfter": {},
"type": "Switch"
}
},
"case": "departments"
}
},
"default": {
"actions": {
"Response_2": {
"inputs": {
"body": "the APICallFor header is not valid",
"statusCode": 500
},
"kind": "Http",
"runAfter": {},
"type": "Response"
}
}
},
"expression": "@body('HeadersJson')?['APICallFor']",
"runAfter": {
"HeadersJson": [
"Succeeded"
]
},
"type": "Switch"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {
"properties": {
"searchString": {
"type": "string"
},
"searchType": {
"type": "string"
}
},
"type": "object"
}
},
"kind": "Http",
"operationOptions": "EnableSchemaValidation",
"type": "Request"
}
}
}
}

最佳答案

你的表达式无效是因为你的表达式中的@@表达式是在代码 View 中使用的,它应该只是body('HeadersJson' )?['searchType'].

至于您的 searchType 为 null,可能是 ParseJson 架构不正确,因此请确保正确的架构为 doc way .

如果您想使用 header 数据,则不需要将 header 解析为 json,因为数据已经是 json 格式,但是如果您通过请求正文传递数据,则需要解析它。我也测试过它,它将与 triggerOutputs()['headers']['searchType'] 一起使用,所以只需将其粘贴到表达式中,如果您使用代码 View ,它将是 @triggerOutputs()['headers']['searchType']

enter image description here

enter image description here

关于azure - 逻辑应用无法从解析 JSON 操作中找到值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56337946/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com