您好我有這樣的XML -轉換XML的成JSON
這是一個基於XML
<item col_sort='20160102' Month='Jan-2016' Week='Week 1' Date='01/02/2016' Name='A' Id='1'
Column1='0' Column1Agg1='1410.00' Column1Agg2='405.00' Column1Agg3='0'
Column2='38' Column2Agg1='2976' Column2Agg2='79' Column2Agg3='79'
Column3='0.32' Column3Agg1='0.56' Column3Agg2='0.41' Column3Agg3='0.41'
Column4='11.42' Column4Agg1='8.48' Column4Agg2='9.55' Column4Agg3='9.55'
Column5='8.76' Column5Agg1='2.97' Column5Agg2='9.81' Column5Agg3='9.81'
Column6='-1' Column6Agg1='-2' Column6Agg2='-1' Column6Agg3='-1'
Column7='-99' Column7Agg1='99.9' Column7Agg2='-99' Column7Agg3='-99'
Column8='-99.00' Column8Agg1='8.00' Column8Agg2='-99.00' Column8Agg3='-99.00'
Column9='17.82' Column9Agg1='9.96' Column9Agg2='17.84' Column9Agg3='17.84'
Column10='18.18' Column10Agg1='10.51' Column10Agg2='18.28' Column10Agg3='18.28'
Column11='-2' Column11Agg1='-2' Column11Agg2='-2' Column11Agg3='-2'
Column12='7.9' Column12Agg1='44.6' Column12Agg2='7.6' Column12Agg3='7.6'
Column13='12.86' Column13Agg1='10.48' Column13Agg2='12.68' Column13Agg3='12.68' />
的節點現在,這裏的AGG的前綴的子節點。因此,在一個節點中,我們讓所有的孩子都與父母一起重視。這裏的Agg1代表父母。 Agg2是Agg1的孩子,Agg3是Agg2的孩子。沒有前綴的節點是葉節點。
json = [ {
"Month": "Dec-2016",
"Column1Agg1": "1410.00",
"Column2Agg1": "2976",
"Column3Agg1": "0.56",
"Column4Agg1": "8.48",,
"Column5Agg1": "2.97",
"Column6Agg1": "-2",
"Column7Agg1": "-99.9",
"Column8Agg1": "8.00",
"Column9Agg1": "9.96",
"Column10Agg1": "10.51",
"Column11Agg1": "-2",
"Column12Agg1": "44.6",
"Column13Agg1": "10.48",
"children" : [
{"Week": "Week 1",
"Column1Agg2": "405.00",
"Column2Agg2": "79",
"Column3Agg2": "0.41",
"Column4Agg2": "9.55",
"Column5Agg2": "9.81",
"Column6Agg2": "-1",
"Column7Agg2": "-99",
"Column8Agg2": "-99.00",
"Column9Agg2": "17.84",
"Column10Agg2": "18.28",
"Column11Agg2": "-2",
"Column12Agg2": "7.6",
"Column13Agg2": "12.68",
"children" : [{
"Date": "01/02/2016",
"Column1Agg3": "405.00",
"Column2Agg3": "79",
"Column3Agg3": "0.41",
"Column4Agg3": "9.55",
"Column5Agg3": "9.81",
"Column6Agg3": "-1",
"Column7Agg3": "-99",
"Column8Agg3": "-99.00",
"Column9Agg3": "17.84",
"Column10Agg3": "18.28",
"Column11Agg3": "-2",
"Column12Agg3": "7.6",
"Column13Agg3": "12.68",
"children" : [{
"Name" : "A",
"Id" : "1",
"Column1": "0",
"Column2": "38",
"Column3": "0.32",
"Column4": "11.42",
"Column5": "8.76",
"Column6": "-1",
"Column7": "-99",
"Column8": "-99.00",
"Column9": "17.82",
"Column10": "18.18",
"Column11": "-2",
"Column12": "7.9",
"Column13": "12.86"
}]
}]
}]
}]
如何將這種類型的xml轉換爲帶有子項的json。
任何想法如何做到這一點
請同時添加一個問題。你描述過什麼,你有什麼問題? –
打開google並輸入「javascript xml to json」並點擊第一個鏈接。 –
@TahaPaksu它不會創建子節點,它只會轉換...我想創建子節點 – shv22