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

如何在Azure Logic App中重命名比特币行情JSON字段并生成CSV表

解决方案

问题根因

  • 第一,For Each循环内的Compose仅构造了pair单个属性,未保留原响应的id、price、volume等其他字段,即使能拿到输出也不符合格式要求
  • 第二,Azure Logic App的Foreach类型动作本身没有默认的body返回值,直接引用@body('For_each')必然会获取到null值,导致Create CSV table动作报错

修正后的完整工作流代码

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Create_CSV_table": {
                "inputs": {
                    "format": "CSV",
                    "from": "@variables('转换后的行情数组')"
                },
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "Table"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "转换后的行情数组",
                            "type": "Array"
                        }
                    ]
                },
                "runAfter": {
                    "Parse_JSON": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "For_each": {
                "actions": {
                    "Compose": {
                        "inputs": {
                            "id": "@items('For_each')?['id']",
                            "pair": "@items('For_each')?['market']",
                            "price": "@items('For_each')?['price']",
                            "volume": "@items('For_each')?['volume']",
                            "funds": "@items('For_each')?['funds']",
                            "created_at": "@items('For_each')?['created_at']",
                            "side": "@items('For_each')?['side']"
                        },
                        "runAfter": {},
                        "type": "Compose"
                    },
                    "Append_to_array_variable": {
                        "inputs": {
                            "name": "转换后的行情数组",
                            "value": "@outputs('Compose')"
                        },
                        "runAfter": {
                            "Compose": [
                                "Succeeded"
                            ]
                        },
                        "type": "AppendToArrayVariable"
                    }
                },
                "foreach": "@body('Parse_JSON')",
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach",
                "runtimeConfiguration": {
                    "concurrency": {
                        "repetitions": 1
                    }
                }
            },
            "HTTP": {
                "inputs": {
                    "method": "GET",
                    "uri": "https://api.wazirx.com/api/v2/trades?market=btcusdt"
                },
                "runAfter": {},
                "type": "Http"
            },
            "Parse_JSON": {
                "inputs": {
                    "content": "@body('HTTP')",
                    "schema": {
                        "items": {
                            "properties": {
                                "created_at": {
                                    "type": "string"
                                },
                                "funds": {
                                    "type": "string"
                                },
                                "id": {
                                    "type": "integer"
                                },
                                "market": {
                                    "type": "string"
                                },
                                "price": {
                                    "type": "string"
                                },
                                "side": {},
                                "volume": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "id",
                                "market",
                                "price",
                                "volume",
                                "funds",
                                "created_at",
                                "side"
                            ],
                            "type": "object"
                        },
                        "type": "array"
                    }
                },
                "runAfter": {
                    "HTTP": [
                        "Succeeded"
                    ]
                },
                "type": "ParseJson"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    }
}

核心修改说明

  • 新增数组变量用于收集转换后的每一条数据,解决For Each无默认输出的问题
  • 调整Compose动作的输入,保留原始所有字段的同时将market重命名为pair
  • 关闭For Each的并发执行,避免数组追加顺序混乱
  • 将Create CSV table的输入源改为自定义的数组变量

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 12:54:00