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

技术请求:将指定JSON编码数据转换为目标精简格式

处理JSON数据字段转换的解决方案

没问题,我来帮你搞定这个JSON数据的转换需求!我们可以用JavaScript轻松实现你要的效果,具体步骤和代码如下:

实现思路

  1. 遍历原始数组中的每个对象
  2. 保留project_name字段不变
  3. 将BookedUnit字段重命名为Unit,并把字符串类型的数值转换为数值类型
  4. 自动忽略不需要的GDV字段(因为新对象里不包含它)

代码示例

// 原始JSON数据
const originalData = [
  { project_name: "Faithview 1 Residence", BookedUnit: "25", GDV: "9,143,860.00" },
  { project_name: "Faithview 2 Residence", BookedUnit: "24", GDV: "8,795,380.00" },
  { project_name: "Faithview 3 Residence", BookedUnit: "24", GDV: "8,795,380.00" }
];

// 执行转换
const transformedData = originalData.map(item => ({
  project_name: item.project_name,
  Unit: parseInt(item.BookedUnit, 10) // 把字符串转成整数类型
}));

// 输出结果
console.log(transformedData);

转换后的结果

运行上面的代码后,你会得到符合要求的结果:

[
  { "project_name": "Faithview 1 Residence", "Unit": 25 },
  { "project_name": "Faithview 2 Residence", "Unit": 24 },
  { "project_name": "Faithview 3 Residence", "Unit": 24 }
]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 09:47:08