如何从数组中删除引号

时间:2015-04-14 17:37:02

标签: jquery arrays json

 $.getJSON('data.json', function(data) {
        var arr = [];

        for(var i = 0, j = data.length; i < j; i++)
        {
            var param = data[i];

            if(param['p'] == 'levelA')
            {
            arr.push('{"x":'+param['t']+','+'"y":0'+','+'"h":'+param['v']+','+'"w":1,'+'"bg":"magenta"}');
            }   
        }
    })

此代码返回

["{"x":5.07527,"y":0,"h":0,"w":1,"bg":"magenta"}", "{"x":5.08601,"y":0,"h":7,"w":1,"bg":"magenta"}", "{"x":5.09164,"y":0,"h":12,"w":1,"bg":"magenta"}", "{"x":5.10255,"y":0,"h":19,"w":1,"bg":"magenta"}", "{"x":5.11356,"y":0,"h":26,"w":1,"bg":"magenta"}"....

我需要卸妆“”,转发这个

"{"x":5.07527,"y":0,"h":0,"w":1,"bg":"magenta"}"

要      { “×”:5.07527, “Y”:0, “H”:0, “W”:1, “BG”: “品红”}

1 个答案:

答案 0 :(得分:2)

不要将字符串推入arr,推送对象:

arr.push({ x: param.t, y: 0, h: param.v, w: 1, bg: "magenta" });