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

如何从给定JSON数据中提取所有itog字段值并返回对应新数组

JSON字段提取实现方案

核心逻辑

  • 遍历源JSON数组的所有顶层元素
  • 依次读取每个元素下0属性对应的对象
  • 提取该对象中itog字段的数值
  • 将所有数值汇总为新数组即为目标结果

代码实现示例

JavaScript版本

const sourceData = [
    {
      "0": {
        "itog": 12860498,
        "return": 1107294,
        "beznal": 10598131
      },
      "date": "2021-01-31"
    },
    {
      "0": {
        "itog": 20156554,
        "return": 1147363,
        "beznal": 18127393
      },
      "date": "2021-02-28"
    },
    {
      "0": {
        "itog": 19187309,
        "return": 1667656,
        "beznal": 17597434
      },
      "date": "2021-03-31"
    }
];
const result = sourceData.map(item => item['0'].itog);

Python版本

source_data = [
    {
      "0": {
        "itog": 12860498,
        "return": 1107294,
        "beznal": 10598131
      },
      "date": "2021-01-31"
    },
    {
      "0": {
        "itog": 20156554,
        "return": 1147363,
        "beznal": 18127393
      },
      "date": "2021-02-28"
    },
    {
      "0": {
        "itog": 19187309,
        "return": 1667656,
        "beznal": 17597434
      },
      "date": "2021-03-31"
    }
]
result = [item['0']['itog'] for item in source_data]

最终输出结果

[12860498, 20156554, 19187309]

内容的提问来源于stack exchange,提问作者Васили

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 20:15:03