使用另一个JSON中的少量列创建JSON

时间:2017-05-09 19:25:27

标签: json

我有一个JSON文件如下:

[{"PROV_32_ID":1.0,"Pname":"Kabul","Time":9107,"value":24.0,"Children59m":0.0},
 {"PROV_32_ID":1.0,"Pname":"Kabul","Time":9110,"value":92.0,"Children59m":8.0},
 {"PROV_32_ID":1.0,"Pname":"Kabul","Time":9111,"value":78.0,"Children59m":4.0}]

我想创建另一个只有三列的JSON,如下面的JSON对象。

[{"Pname":"Kabul","Time":9107,"value":24.0},
 {"Pname":"Kabul","Time":9110,"value":92.0},
 {"Pname":"Kabul","Time":9111,"value":78.0}]

任何人,请帮忙。

1 个答案:

答案 0 :(得分:0)

您可以使用for循环

<强>已更新

&#13;
&#13;
var json = [{"PROV_32_ID":1.0,"Pname":"Kabul","Time":9107,"value":24.0,"Children59m":0.0},{"PROV_32_ID":1.0,"Pname":"Kabul","Time":9110,"value":92.0,"Children59m":8.0},{"PROV_32_ID":1.0,"Pname":"Kabul","Time":9111,"value":78.0,"Children59m":4.0}]

for(var i in json)
{
	delete json[i]['PROV_32_ID'];
  json[i]['value'] = json[i]['Children59m'];
  delete json[i]['Children59m']; 
}
console.log(json)
&#13;
&#13;
&#13;