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

Flow中使用Parse JSON时如何遍历返回JSON的data数组

问题原因

你在Flow里加Parse JSON动作后读不到data数组,根本不是深度访问的问题,是自动生成JSON Schema的时候出了bug:自动推断逻辑只把结构复杂的resultSetMetaData完整识别写入了Schema,和它同级的data数组、code这些顶层字段直接漏写在Schema里了,解析的时候自然会被过滤掉,不会出现在动态内容列表里。

操作步骤
  • 第一步:补全Parse JSON的Schema
    删掉原来自动生成的残缺Schema,直接把下面完整定义了所有顶层字段(包含data二维数组)的Schema粘贴到Schema输入框,Parse JSON的输入内容还是保持填API返回的原始响应即可:
{
    "type": "object",
    "properties": {
        "resultSetMetaData": {
            "type": "object",
            "properties": {
                "page": {"type": "integer"},
                "numPages": {"type": "integer"},
                "numRows": {"type": "integer"},
                "format": {"type": "string"},
                "rowType": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "name": {"type": "string"},
                            "database": {"type": "string"},
                            "schema": {"type": "string"},
                            "table": {"type": "string"},
                            "type": {"type": "string"},
                            "scale": {},
                            "precision": {},
                            "nullable": {"type": "boolean"},
                            "byteLength": {"type": "integer"},
                            "collation": {},
                            "length": {"type": "integer"}
                        }
                    }
                }
            }
        },
        "data": {
            "type": "array",
            "items": {
                "type": "array",
                "items": {"type": "string"}
            }
        },
        "code": {"type": "string"},
        "statementStatusUrl": {"type": "string"},
        "requestId": {"type": "string"},
        "sqlState": {"type": "string"},
        "statementHandle": {"type": "string"},
        "message": {"type": "string"},
        "createdOn": {"type": "integer"}
    }
}
  • 第二步:遍历data数组
    保存配置后手动跑一次测试触发Flow,再回到动作编辑页,你就能在Parse JSON的动态内容输出里直接看到data字段了。后续直接添加「应用到每一个(Apply to each)」循环动作,循环输入源选Parse JSON输出的data即可,循环过程中每一个当前项,就是data二维数组里的一行单条记录(一维字符串数组)。
  • 第三步(按需配置):字段值映射
    因为返回的行数据是按rowType里的字段顺序排列的位置数组,你可以直接按下标取对应字段的值:比如rowType第0位是FIRST_NAME,那循环里取当前项的第一个名字就写item()[0],姓是item()[1],邮箱是item()[2],和rowType里的字段顺序一一对应就行。
注意事项
  • 不用自己写复杂的层级访问表达式,只要Schema定义正确,所有字段都会自动出现在动态内容面板里,手动拼路径反而容易写错
  • 如果之前生成Schema时用的示例JSON里data是空数组,自动生成逻辑会直接把data字段识别为空对象甚至直接忽略,必须手动在Schema里明确声明data是二维字符串数组类型
  • 你提供的示例返回里,rowType只定义了9个字段,但data里每行有10个值,取数的时候先核对下标对应关系,避免拿错字段值

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.29 17:30:46