我想合併json格式(優先使用下劃線),但不知道它是如何完成的。第一個json沒有要映射的_id指示符。合併兩個json格式基於
JSON 1:
{
"0001": {
"answer": "sad"
},
"0002": {
"answer": "sad1"
}
}
JSON 2:
合併後[
{
"_id": "0001",
"question": "who am I"
},
{
"_id": "0002",
"question": "How old are you?"
}
]
最終結果:
[
{
"_id": "0001",
"question": "who am I",
"answer": "sad"
},
{
"_id": "0002",
"question": "How old are you?",
"answer": "sad1"
}
]
爲方針,我試圖改變JSON 1至以下格式第一但無法實現。
[
{
"_id": "0001",
"answer": "sad"
},
{
"_id": "0002",
"answer": "sad1"
}
]
一樣方便'arr.map(O => { o.answer = obj [o._id] .answer; return o; })'。但我沒有嘗試任何東西。 – Tushar
請看看** JSON 1 **,它不是一個數組。 – Fabricio
@Fabricio是的,我很清楚這一點。 – stackdisplay