gpt4 book ai didi

javascript - 如何删除对象的键和值之间的空格

转载 作者:行者123 更新时间:2023-11-30 09:52:41 29 4
gpt4 key购买 nike

我想在使用 json_decode 方法解码之前删除键或对象名称之间的所有空格。

Income cut 我可以做到 Income_cut 吗?

有没有办法解决这个问题。

{
"Housing": 0,
"Late Comers": 0,
"Income cut": "12500",
"Study Allowance": 0,
"test": 0,
"i": 0,
"staff_no": "9",
"staff_name": "Abeja Vicky",
"staff_department": "Production Staff",
"staff_position": "Production Manager",
"staff_salary": "0",
"GrossValue": 12500,
"GrossSalary": 0,
"NSSF": 0,
"PAYE": 0,
"GrossValueAddiotion": 0,
"GrossValueDecuction": 12500,
"netPay": -12500,
"Balance": 0,
"Paidx": 0,
"balance": -12500
}

最佳答案

假设没有嵌套简单的 json 对象,下面将在发送到服务器之前工作

var input ={
"Housing": 0,
"Late Comers": 0,
"Income cut": "12500",
"Study Allowance": 0,
"test": 0,
"i": 0,
"staff_no": "9",
"staff_name": "Abeja Vicky",
"staff_department": "Production Staff",
"staff_position": "Production Manager",
"staff_salary": "0",
"GrossValue": 12500,
"GrossSalary": 0,
"NSSF": 0,
"PAYE": 0,
"GrossValueAddiotion": 0,
"GrossValueDecuction": 12500,
"netPay": -12500,
"Balance": 0,
"Paidx": 0,
"balance": -12500
}

var output = {};
for(var key in input){
output[key.replace(/\s+/,'_')] = input[key];
}

console.log(output);

关于javascript - 如何删除对象的键和值之间的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35541239/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com