我有一个json字符串:
arguments[0] = [{"one":"1","two":"1","three":"15","four":"esj","five":null,"six":"2015-10-15 00:00:00","seven":null},
{"one":"1","two":"1","three":"15","four":"esj","five":null,"six":"2015-10-15 00:00:00","seven":null},
{"one":"1","two":"1","three":"15","four":"esj","five":null,"six":"2015-10-15 00:00:00","seven":null, ...}]
我希望将其更改为以下格式:
[ '1', '1', '15', 'esj', null, '2015-10-15 00:00:00', null],
[ '1', '1', '15', 'esj', null, '2015-10-15 00:00:00', null],
[ '1', '1', '15', 'esj', null, '2015-10-15 00:00:00', null], etc...
我怎么能在jquery中做到这一点?
编辑:
使用@Joseph这个梦想家的回答我几乎让它成功了,现在我正在使用:
return ["['"+arg.one+"'", "'"+arg.two+"'", "'"+arg.three+"'", "'"+arg.four+"'", "'"+arg.five+"'", "'"+arg.six+"']"]
它让我产生了这个:
[1,2,3,4,5,6],[1,2,3,4,5,6], etc
这很好,但我需要稍后将其转换为字符串。我怎么能这样做?
答案 0 :(得分:2)
实际上不需要jQuery。您所需要的只是map
。
var arr = arguments[0].map(function(arg){
return [arg.one, arg.two, arg.three, arg.four, arg.five, arg.six, arg.seven];
});
Object.keys
可以循环键,但必须保留顺序。另外,我不鼓励修改arguments
。