Json编码数据格式

时间:2018-04-12 07:05:05

标签: json

下面是我的json编码数据,

 [
   {
      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"
   }
 ]

我想更改json数据,如下所示: -

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

新的json数据有3个条件: - 1)删除GDV
2)BookedUnit的键变为Unit 3)“单位”的格式值现在变为Int。

感谢任何建议和解决方案。

1 个答案:

答案 0 :(得分:1)

请检查此解决方案。这适合您



var oldJSON = [{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"}];

var newJSON = [];

for(key in oldJSON){
  newJSON[key] = {project_name : oldJSON[key].project_name, Unit : parseInt(oldJSON[key].BookedUnit)};
}

console.log(newJSON);