给json数据的某一属性增加多个值

可以利用一个list,不断push需要添加进去的值,最后再把这个list赋给json数据中的某个特定属性。

for(var index in res.result.data){
  urls = res.result.data[index].fileIDs
  var urls1=[]
  var s3 = "特长证明材料"
  for (var index1 in urls) {
      if(urls[index1].indexOf(s3)!=-1){
        urls1.push(urls[index1])
      }
  }
  res.result.data[index]["specialty"] = urls1
}

效果

在这里插入图片描述
如果不这样做,这个specialty的属性就只能获得一个值。
暂时还没有想到其他的方法。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现此功能,您需要使用一些 Node.js 模块来解析 Excel 文件并将其转换为 JSON 格式,然后使用 JSON 模块来读取和修改 JSON 数据。以下是一个参考代码示例: ```javascript const xlsx = require('xlsx'); const fs = require('fs'); const jsonfile = require('jsonfile'); // 读取 Excel 文件,并将其转换为 JSON 格式 const workbook = xlsx.readFile('data.xlsx'); const worksheet = workbook.Sheets[workbook.SheetNames[0]]; const jsonData = xlsx.utils.sheet_to_json(worksheet); // 根据需要更改 JSON 数据 const targetRow = 2; // 要更改的 Excel 行数 const targetColumn = 'name'; // 要更改的 Excel 列名 const newValue = 'John Doe'; // 新的属性 jsonData[targetRow - 1][targetColumn] = newValue; // 更新 JSON 数据中的相应属性 // 将修改后的 JSON 数据写回到文件中 const outputFilePath = 'output.json'; jsonfile.writeFile(outputFilePath, jsonData, { spaces: 2 }, (err) => { if (err) { console.error(err); } else { console.log(`File saved as ${outputFilePath}`); } }); ``` 在此示例中,我们使用了 `xlsx` 模块来读取 Excel 文件,将其转换为 JSON 格式。然后,我们指定要更改的行号和列名,以及新的属性。最后,我们使用 `jsonfile` 模块将修改后的 JSON 数据写回到文件中。 请注意,此示例仅适用于 Excel 文件的第一个工作表,并且假定要更改的属性JSON 数据中存在。如果您的 Excel 文件包含多个工作表或要更改的属性不存在,您需要做一些其他修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值