xml格式转成json格式,使用Python
import xml.etree.ElementTree root=xml.etree.ElementTree.parse('testXml.xml') book=root.findall('person') for book_list in book: for note in book_list: print(note.tag+':'+note.text)
f = open('testJson.json','a',encoding="utf-8")
for each in root1.getiterator("person"):
	tempDict = each.attrib
	for childNode in each.getchildren(): # 利用getchildren方法得到子节点
		tempDict[childNode.tag] = childNode.text # tag获取节点名,text获取节点值
	tempJson = json.dumps(tempDict,ensure_ascii=False)
	print(tempJson)
	f.write(tempJson + '\n')
f.close()

 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号