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

如何从返回数据中提取多个firstLanguage对象至单个变量

批量提取firstLanguage对象的实现方法

假设你拿到的批量返回数据是数组/列表形式(比如命名为responseData),里面包含多个你提供的结构对象,以下是几种主流编程语言的实现方式:

JavaScript实现

// 示例批量数据
const responseData = [
  {
    type: 'Text',
    firstLanguage: {
      translation: 'When the Constituent Assembly passed the Objective Resolution?',
      option_a: '14th February 1949',
      option_b: '12th March 1949',
      option_c: '9th June 1949',
      option_d: '15th August 1949',
      correct_answer: 4
    },
    secondLanguage: { /* ... */ }
  },
  // 更多同结构对象...
];

// 提取所有firstLanguage到变量中
const firstLanguageItems = responseData.map(item => item.firstLanguage);

Python实现

# 示例批量数据
response_data = [
    {
        'type': 'Text',
        'firstLanguage': {
            'translation': 'When the Constituent Assembly passed the Objective Resolution?',
            'option_a': '14th February 1949',
            'option_b': '12th March 1949',
            'option_c': '9th June 1949',
            'option_d': '15th August 1949',
            'correct_answer': 4
        },
        'secondLanguage': { ... }
    },
    # 更多同结构字典...
]

# 提取所有firstLanguage到变量中
first_language_items = [item['firstLanguage'] for item in response_data]

Java实现

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class DataExtractor {
    public static void main(String[] args) {
        // 示例批量数据
        List<Map<String, Object>> responseData = new ArrayList<>();
        // 填充批量数据...

        // 提取所有firstLanguage到变量中
        List<Map<String, Object>> firstLanguageItems = new ArrayList<>();
        for (Map<String, Object> item : responseData) {
            firstLanguageItems.add((Map<String, Object>) item.get("firstLanguage"));
        }
    }
}

核心逻辑一致:遍历批量数据集合,逐个提取每个元素中的firstLanguage属性,将结果存入新的集合变量中。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 11:37:01