【问题标题】:How to use change JSON structure using Compose action in Azure Logic Apps?如何在 Azure 逻辑应用中使用 Compose 操作更改 JSON 结构?
【发布时间】:2019-07-24 08:07:38
【问题描述】:

我正在尝试更改从我使用这样的逻辑应用发出的请求中获得的 JSON 响应:

此请求将得到以下响应:

{
"invoiceID":1,
"formType":"invoice",
"amount":449,
"currency":"eur",
"description":"Invoice real estate",
"period":{"end":20122019,"start":20122020},
"owner":{
   "id":91434,
   "firstname":"John",
   "lastname":"Doe",
   "dateOfBirth":1121993,
   "phoneNumber":345435435,
   "countryOfBirth":"Nederland",
   "IBAN":"NL28 ABNA 743734g763474324"
},
"property":{
   "id":105,
   "type":"apartment",
   "address":"ghost lane 13",
   "ZIP":"7888 CK",
   "State\/Province":"Groningen",
   "country":"Nederland",
   "construction-year":15072009,
   "previousOwners":9
},
"previousProperties":[54,193,11,454,18]
}

现在我正在尝试将上面的 JSON 组合成另一个 json 结构,例如:

{
"general": {
    "invoiceID": 12,
    "formType": "invoice",
    "amount": 449,
    "currency": "eur",
    "description": "Invoice real estate",
    "period": {
       "end": 20122019,
       "start": 20122020
    }
 }
 }

我尝试为此使用 Compose 操作:

最后我返回响应:

]]

此设置不起作用,我收到以下错误:

{"error":{"code":"NoResponse","message":"服务器没有收到upstream-server的应答。请求的trace-id是08586376520125765844944852801CU36。"}}

当我从逻辑应用设计器中删除 Compose 操作时,流程确实有效,但我得到的是原始 JSON 响应。

更新

我的撰写配置有以下选项:

【问题讨论】:

    标签: json azure azure-logic-apps


    【解决方案1】:

    从您的图片中,您的响应正文设置了 HTTP 操作正文,您需要设置 Compose 输出,以下是我的测试结果,我没有收到您的错误。也许你可以看看。并且看起来在您的撰写操作中,您将值设置为错误的值,根据您的要求,您需要使用HTTP 设置它们以获取操作输出。

    我使用 HTTP 触发器进行测试。

    以下是我的撰写输入:

    "general": {
                            "amount": "@body('HTTP')['amount']",
                            "currency": "@body('HTTP')['currency']",
                            "description": "@body('HTTP')['description']",
                            "formType": "@body('HTTP')['formType']",
                            "invoiceID": "@body('HTTP')['invoiceID']",
                            "period": {
                                "end": "@body('HTTP')['period']['end']",
                                "start": "@body('HTTP')['period']['start']"
                            }
                        }
    

    这是我的邮递员得到的回应。

    希望对你有帮助。

    【讨论】:

    • 看起来不错,但如果我将响应操作的主体更改为输出,我仍然会遇到同样的错误。我还用邮递员对此进行了测试。
    • 你在“And below is my compose output”处显示的代码,我如何找到这个?
    • 查看我为撰写操作获得的选项的更新。
    • 我在代码视图中设置的撰写输入,您也可以使用表达式进行设置。
    • 也许你可以去代码视图并使用我的撰写输入进行测试。code view
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    • 1970-01-01
    • 2019-03-11
    • 2021-03-20
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多