【发布时间】:2016-03-17 22:56:12
【问题描述】:
我有一个数组,像这样:
["1", "hello1@example.com", "user111", "something1"],
["2", "hello2@example.com", "user222", "something2"],
["3", "hello3@example.com", "user333", "something3"],
...
["N", "helloN@example.com", "userNNN", "somethingN"]
我怎样才能把它变成这样的 JSON:
{
"order" : "1"
, "email": "hello1@example.com"
, "username": "user111"
, "note": "something1"
},
{
"order" : "2"
, "email": "hello2@example.com"
, "username": "user222"
, "note": "something2"
},
{
"order" : "3"
, "email": "hello3@example.com"
, "username": "user333"
, "note": "something3"
},
...
{
"order" : "N"
, "email": "helloN@example.com"
, "username": "userNNN"
, "note": "somethingN"
}
我是自学 JavaScript,如果您能推荐一个类似的案例或文档以了解更多信息,我将不胜感激。
谢谢。
【问题讨论】:
-
我正在考虑通过内部数组运行一个for循环,取出第一项“1”并将“order”:“1”放回去,取出第二项“hello1@example .com”并放回“email”:“hello1@example.com”等等,直到我有一个正确的“name:value”配对数组,然后使用 json.stringify() 该数组。这是好方法吗?
标签: javascript arrays json