Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 大容量XML到JSON转换_Python_Json_Xml_Parsing - Fatal编程技术网

Python 大容量XML到JSON转换

Python 大容量XML到JSON转换,python,json,xml,parsing,Python,Json,Xml,Parsing,有谁能推荐一些好的XML到JSON转换工具/脚本来转换超过100万条XML记录吗?您不需要Python 您应该能够很容易地使用来实现这一点。您不需要Python 您应该能够很容易地使用来实现这一点。实现这一点的一种方法是将xml转换为dict,然后将dict转换为JSON。下面是一个简单的例子 import json import xmltodict def convertXmlToJSON(xmlFile, xml_attribs=True): with open(xmlFile,

有谁能推荐一些好的XML到JSON转换工具/脚本来转换超过100万条XML记录吗?

您不需要Python


您应该能够很容易地使用来实现这一点。

您不需要Python


您应该能够很容易地使用来实现这一点。

实现这一点的一种方法是将xml转换为dict,然后将dict转换为JSON。下面是一个简单的例子

import json
import xmltodict

def convertXmlToJSON(xmlFile, xml_attribs=True):
    with open(xmlFile, "rb") as file:
        my_dict = xmltodict.parse(file, xml_attribs=xml_attribs)
        return json.dumps(my_dict, indent=4,separators=(',', ': '))

一种方法是将xml转换为dict,然后将dict转换为JSON。下面是一个简单的例子

import json
import xmltodict

def convertXmlToJSON(xmlFile, xml_attribs=True):
    with open(xmlFile, "rb") as file:
        my_dict = xmltodict.parse(file, xml_attribs=xml_attribs)
        return json.dumps(my_dict, indent=4,separators=(',', ': '))

xml2json.js是一个用于将xml文件转换为json格式的js库,您可以使用此脚本编写一个小程序,或者尝试我的在线xml-to-json转换器,您可以在一次单击中转换多个xml文件,使用xml2json.jsxml2json.js是一个用于将xml文件转换为json格式的js库,您可以使用此脚本创建一个小程序,或者尝试我的在线xml-to-json转换器,您可以在一次单击中转换多个xml文件,使用xml2json.js创建