我對這個json /數組很新,下面的數據來自一個表,並且我需要將它移植到另一個表中,這需要我根據ID最高的國家進行排序... 在加載的國家是動態... 感激,如果有人可以告訴我,我怎麼能集團的所有國家劃分爲「國家」,並推到我試圖做正確的數據[I]如何迭代和替換JSON
var data = [
{"Product": "DESKTOP", "Type": "APPLE" , "CN": "", "IN": "", "SG": "20"},
{"Product": "DESKTOP", "Type": "DELL" , "CN": "", "IN": "", "SG": "20"},
{"Product": "LAPTOP", "Type": "XXX", "CN": "", "IN": "90", "SG": "28"},
{"Product": "MOBILE", "Type": "XXX","CN": "1","IN": "","SG": "28"},
{"Product": "TABLET", "Type": "XXX","CN": "13","IN": "","SG": "238"}
]
what_i_need = [
{"Product": "DESKTOP",
"Type": "APPLE",
"Country": [
{"country": "CN", "id": ""}
{"country": "IN", "id": ""}
{"country": "SG", "id": "20"}
]},
...
...
]
循環但它結束了像這樣
[{"country": "CN", "id": ""}
{"country": "IN", "id": ""}
{"country": "SG", "id": "20"}
{"country": "CN", "id": ""}
{"country": "IN", "id": ""}
{"country": "SG", "id": "20"}
把你的代碼,來生成陣列,並會幫助您更好地 –
你能分享你的代碼和嘗試? – yashgarg1232
當我試圖生成陣列時,h77和Shiladitya發佈了答案,非常感謝!我希望我能給shiladitya打勾,但是h77拿到了最快的一手牌。不勝感激! – tpb