如何删除JSON中列名的双引号?

时间:2018-04-17 01:55:27

标签: javascript json ajax

我的ajax返回数据(json)是这样的:

data:[{"employeeCode":10061600,"working":5,"beforeWork":11,"employeeName":"Tom"},
  {"employeeCode":10071407,"working":4,"beforeWork":12,"employeeName":"Peter"},
  {"employeeCode":10072570,"working":5,"beforeWork":12,"employeeName":"Kate"}
   ]

我想删除每个列名称的双引号。我想要这个结果:

 data:[{employeeCode:10061600,working:5,beforeWork:11,employeeName:"Tom"},
  {employeeCode:10071407,working:4,beforeWork:12,employeeName:"Peter"},
  {employeeCode:10072570,working:5,beforeWork:12,employeeName:"Kate"}
   ]

怎么做? 我需要将数据更改为这种格式,因为我使用highcharts,在highcharts中,它允许这种格式数据:

data: [
        { x: 95, y: 95, z: 13.8, name: 'BE', country: '比利时' },
        { x: 86.5, y: 102.9, z: 14.7, name: 'DE', country: '德国' },
        { x: 80.8, y: 91.5, z: 15.8, name: 'FI', country: '芬兰' },
        { x: 80.4, y: 102.5, z: 12, name: 'NL', country: '荷兰' },
        { x: 80.3, y: 86.1, z: 11.8, name: 'SE', country: '瑞典' },
        { x: 78.4, y: 70.1, z: 16.6, name: 'ES', country: '西班牙' },
        { x: 74.2, y: 68.5, z: 14.5, name: 'FR', country: '法国' },
        { x: 73.5, y: 83.1, z: 10, name: 'NO', country: '挪威' },
        { x: 71, y: 93.2, z: 24.7, name: 'UK', country: '英国' },
        { x: 69.2, y: 57.6, z: 10.4, name: 'IT', country: '意大利' },
        { x: 68.6, y: 20, z: 16, name: 'RU', country: '俄罗斯' },
        { x: 65.5, y: 126.4, z: 35.3, name: 'US', country: '美国' },
        { x: 65.4, y: 50.8, z: 28.5, name: 'HU', country: '匈牙利' },
        { x: 63.4, y: 51.8, z: 15.4, name: 'PT', country: '葡萄牙' },
        { x: 64, y: 82.9, z: 31.3, name: 'NZ', country: '新西兰' }
     ]

所以我需要删除双引号。

1 个答案:

答案 0 :(得分:1)

根据this question,引号与用于高级图表的Javascript对象没有区别。此外,当JSON转换为JS对象时,双引号将被忽略,而不是对象键的一部分。