javascript - 如何将 json 字符串转换为特定格式?

标签 javascript jquery json

我有一个 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 

这很好,但我需要稍后将其转换为字符串。我怎样才能做到这一点?

最佳答案

实际上不需要 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来循环遍历键,但必须保留顺序。另外,我不鼓励修改参数

关于javascript - 如何将 json 字符串转换为特定格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33223848/

相关文章:

javascript继承模式比较

javascript - MVC3 不显眼的验证器会出现在 Webforms 中吗

javascript - 删除脚本后不会加载 HTML 页面

c# - ASP.Net 如何使用 javascript 迭代网格中的所有行

javascript - window.location.replace 有时不运行

Web2py 中的 Javascript 轮询

javascript - 如何使用 jQuery 动态更改 div 的渐变

c# - 为什么我的内部数组没有被反序列化?

javascript - 加载fabric.js JSON后位置错误

c# - 如何仅使用动态将 JSON 反序列化为简单的 Dictionary<string,object> 到 datagridview?