JavaScript 或 Ruby。重新格式化 JSON 对象
我需要将这个 JSON 对象:
[
[
"[email protected]"
],
[
"[email protected]"
],
[
"[email protected]"
],
[
"[email protected]"
]
]
变成这样:
{
"data": [
{
"email": "[email protected]"
},
{
"email": "[email protected]"
},
{
"email": "[email protected]"
},
{
"email": "[email protected]"
}
] }
这是如何完成的?
I need to turn this JSON object:
[
[
"[email protected]"
],
[
"[email protected]"
],
[
"[email protected]"
],
[
"[email protected]"
]
]
Into this:
{
"data": [
{
"email": "[email protected]"
},
{
"email": "[email protected]"
},
{
"email": "[email protected]"
},
{
"email": "[email protected]"
}
] }
How is this done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,这实际上只是一个数组的数组,但这不是重点。只需循环数组数组并将相关数据推送到对象中的新数组即可:
工作演示。
Well, that's really just an array of arrays, but that's besides the point. Just loop through the array of arrays and push the relevant data onto the new array in your object:
Working demo.
JavaScript:
Javascript:
你可以在这里测试它:
http://jsfiddle.net/v3fnk/
you can test it here:
http://jsfiddle.net/v3fnk/