You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Logic App无法将JSON中Data数组赋值给变量并返回响应

问题:Azure Logic App返回Data数组时出现NoResponse错误

我正在创建首个Azure Logic App,用来过滤第三方API的查询结果。该API返回两类数据:SearchSummary(对象)和Data(数组)。我希望只在响应里返回Data数组,但一直遇到以下错误:

{
    "error": {
        "code": "NoResponse",
        "message": "The server did not receive a response from an upstream server. Request tracking id '08584773567277623430271089584CU00'."
    }
}

如果把变量赋值从@body('Parse_JSON')?['Data']改成@body('Parse_JSON')?['SearchSummary'],SearchSummary能正常返回。我试过追加.items,没用。当我在响应里返回length(@body('Parse_JSON')?['Data'])时,能得到准确的数值,说明Data数组里确实有数据。有人能解释我哪里错了吗?


Logic App代码视图

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Create_Contacts_Array": {
                "inputs": {
                    "variables": [
                        {
                            "name": "OnlineContacts",
                            "type": "array",
                            "value": "@body('Parse_JSON')?['Data']"
                        }
                    ]
                },
                "runAfter": {
                    "Parse_JSON": [
                        "SUCCEEDED"
                    ]
                },
                "type": "InitializeVariable"
            },
            "HTTP": {
                "inputs": {
                    "headers": {
                        "ApiToken": "XXX"
                    },
                    "method": "GET",
                    "uri": "https://api.companysearch.com/v1/data?query=X+Y+Z"
                },
                "runAfter": {},
                "type": "Http"
            },
                        "Parse_JSON": {
                "inputs": {
                    "content": "@body('HTTP')",
                    "schema": {
                        "properties": {
                            "Data": {
                                "items": {
                                    "properties": {
                                        "MEMBERSHIP_DATA": {
                                            "items": {
                                                "properties": {
                                                    "companyId": {
                                                        "type": [
                                                            "string",
                                                            "null"
                                                        ]
                                                    },
                                                    "companyName": {
                                                        "type": [
                                                            "string",
                                                            "null"
                                                        ]
                                                    },
                                                    "dept": {
                                                        "type": [
                                                            "string",
                                                            "null"
                                                        ]
                                                    },
                                                    "endDate": {
                                                        "type": [
                                                            "string",
                                                            "null"
                                                        ]
                                                    },
                                                    "startDate": {
                                                        "type": [
                                                            "string",
                                                            "null"
                                                        ]
                                                    },
                                                    "status": {
                                                        "type": [
                                                            "string",
                                                            "null"
                                                        ]
                                                    },
                                                    "title": {
                                                        "type": [
                                                            "string",
                                                            "null"
                                                        ]
                                                    }
                                                },
                                                "type": "object"
                                            },
                                            "type": "array"
                                        },
                                        "birthdate": {
                                            "type": [
                                                "string",
                                                "null"
                                            ]
                                        },
                                        "dirId": {
                                            "type": [
                                                "string",
                                                "null"
                                            ]
                                        },
                                        "firstName": {
                                            "type": [
                                                "string",
                                                "null"
                                            ]
                                        },
                                        "lastName": {
                                            "type": [
                                                "string",
                                                "null"
                                            ]
                                        },
                                        "middleName": {
                                            "type": [
                                                "string",
                                                "null"
                                            ]
                                        }
                                    },
                                    "type": "object"
                                },
                                "type": "array"
                            },
                            "SearchSummary": {
                                "properties": {
                                    "DatabaseInfo": {
                                        "properties": {
                                            "IndexationDate": {},
                                            "ReleaseNumber": {
                                                "type": "string"
                                            },
                                            "UpdateDate": {
                                                "type": "string"
                                            },
                                            "UpdateNumber": {
                                                "type": "string"
                                            },
                                            "VersionNumber": {
                                                "type": "string"
                                            }
                                        },
                                        "type": "object"
                                    },
                                    "Offset": {
                                        "type": "integer"
                                    },
                                    "RecordsReturned": {
                                        "type": "integer"
                                    },
                                    "Sort": {},
                                    "TotalRecordsFound": {
                                        "type": "integer"
                                    }
                                },
                                "type": "object"
                            }
                        },
                        "type": "object"
                    }
                },
                "runAfter": {
                    "HTTP": [
                        "SUCCEEDED"
                    ]
                },
                "type": "ParseJson"
            },
            "Response": {
                "inputs": {
                    "body": "@variables('OnlineContacts')",
                    "statusCode": "@outputs('HTTP')?['statusCode']"
                },
                "kind": "Http",
                "runAfter": {
                    "Create_Contacts_Array": [
                        "SUCCEEDED"
                    ]
                },
                "type": "Response"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "triggers": {
            "When_a_HTTP_request_is_received": {
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "kind": "Stateless"
}

HTTP请求返回的示例JSON负载

{
    "SearchSummary": {
        "TotalRecordsFound": 48,
        "Offset": 0,
        "RecordsReturned": 48,
        "DatabaseInfo": {
            "ReleaseNumber": "43",
            "UpdateNumber": "431",
            "UpdateDate": "2024-08-20T00:00:00",
            "VersionNumber": "129.00",
            "IndexationDate": null
        },
        "Sort": null
    },
    "Data": [
        {
            "birthdate": "1950-06-01T00:00:00",
            "firstName": "Ian",
            "middleName": "Charlie",
            "lastName": "Jones",
            "dirId": "P003577888",
            "MEMBERSHIP_DATA": [
                {
                    "companyId": null,
                    "companyName": null,
                    "startDate": null,
                    "status": null,
                    "endDate": null,
                    "title": null,
                    "dept": null
                }
            ]
        },
        {
            "birthdate": "1919-05-11T00:00:00",
            "firstName": "Dorothy",
            "middleName": "June",
            "lastName": "Perkins",
            "dirId": "P003890700",
            "MEMBERSHIP_DATA": [
                {
                    "companyId": null,
                    "companyName": null,
                    "startDate": null,
                    "status": null,
                    "endDate": null,
                    "title": null,
                    "dept": null
                }
            ]
        },
        {
            "birthdate": "1947-11-09T00:00:00",
            "firstName": "Paul",
            "middleName": "Dean",
            "lastName": "Doe",
            "dirId": "P003890600",
            "MEMBERSHIP_DATA": [
                {
                    "companyId": "GB04969800",
                    "companyName": "Acme Ltd 1",
                    "startDate": "2020-04-15T00:00:00",
                    "status": "Current",
                    "endDate": null,
                    "title": "Director",
                    "dept": "Board of Directors; Senior management"
                },
                {
                    "companyId": "GB07346800",
                    "companyName": "Acme Ltd 2",
                    "startDate": "2010-08-16T00:00:00",
                    "status": "Current",
                    "endDate": null,
                    "title": "Director",
                    "dept": "Board of Directors; Senior management"
                },
                {
                    "companyId": "GB06741800",
                    "companyName": "Acme Ltd 3",
                    "startDate": "2008-11-04T00:00:00",
                    "status": "Current",
                    "endDate": null,
                    "title": "Director",
                    "dept": "Board of Directors; Senior management"
                }
            ]
        }
    ]
}

解答

你遇到的NoResponse错误,主要和以下几个原因有关,对应解决方法如下:

1. Stateless Logic App响应大小限制

Stateless Logic App的HTTP响应有默认大小限制(通常为100MB),且对响应的生成时间有严格要求。SearchSummary是小型对象,所以能快速返回;而Data数组包含大量嵌套数据,可能因数据量过大或序列化耗时过长触发超时,导致NoResponse错误。

  • 解决:如果数据量较大,改用Stateful Logic App(响应大小限制更高,且允许更长的处理时间);或者先对Data数组做分页处理,只返回少量数据测试。

2. Parse_JSON Schema的不完整定义

你的Schema中IndexationDate和Sort字段仅用{}表示,未指定类型。虽然示例数据中是null,但这种不完整定义会导致Parse_JSON动作解析数据时出现隐性错误,后续序列化返回时触发异常。

  • 解决:修改Schema中这两个字段的定义,明确支持null和对应类型:
    "IndexationDate": {
        "type": ["string", "null"]
    },
    "Sort": {
        "type": ["object", "null"]
    }
    

3. 不必要的变量初始化步骤

你当前先将Data数组赋值给变量,再通过变量返回。这一步骤增加了中间环节,可能引入不必要的序列化问题。

  • 解决:直接在Response动作的body中返回@body('Parse_JSON')?['Data'],跳过变量初始化步骤,减少潜在问题。

测试建议

  1. 先返回Data数组的单个元素(如@body('Parse_JSON')?['Data'][0]),验证是否能正常响应,以此判断是数组整体的大小问题还是序列化异常。
  2. 查看Logic App运行历史中Parse_JSON动作的输出,确认Data数组被完整解析,没有截断或格式错误。

内容的提问来源于stack exchange,提问作者InvalidSyntax

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 13:10:56