{"data": {
"char": [
[
[],
[29, "新", "心", "char_2"],
[]
]
],
"miss": [
[
[29, "新", "心", "miss_1"],
[],
[29, "新", "心", "miss_2"],
]
],
"order": [
[]
]
}}
转换为
{"event_list": [
{
"big": {
"type": "char"
},
"small": [
{
"type": "",
"correct": "",
"text": "",
"pos": "",
"index": 0
},
{
"type": "char_2",
"correct": "心",
"text": "新",
"pos": 10,
"index": 1
},
{
"type": "",
"correct": "",
"text": "",
"pos": "",
"index": 2
},
]
},
{
"big": {
"type": "miss"
},
"small": [
{
"type": "miss_1",
"correct": "心",
"text": "新",
"pos": 20,
"index": 0
},
{
"type": "",
"correct": "",
"text": "",
"pos": "",
"index": 1
},
{
"type": "miss_2",
"correct": "心",
"text": "新",
"pos": 10,
"index": 2
}
]
}
]}
###不知道你pos
字段怎么转换的,权且当做那个29
吧:
Object.keys(data)
.map(key => {
return {
big: {
type: key
},
small: data[key][0].map((ele, inx) => {
return {
type: ele[3] || '',
corrent: ele[2] || '',
text: ele[1] || '',
pos: ele[0] || '',
index: inx
}
})
}
})