将json转换为xml的简单python库

json2xml的Python项目详细描述


json2xml

https://img.shields.io/pypi/v/json2xml.svghttps://img.shields.io/travis/vinitkumar/json2xml.svgDocumentation StatusUpdateshttps://coveralls.io/repos/github/vinitkumar/json2xml/badge.svg?branch=master

将json转换为xml的简单python库

功能

它允许您通过以下方式将json转换为xml:

  • 从ajsonstring
  • json文件
  • 从发出json数据的api

使用量

用法很简单:

fromjson2xmlimportjson2xml,readfromurl,readfromstring,readfromjson# get the xml from an URL that return jsondata=readfromurl("https://coderwall.com/vinitcool76.json")print(json2xml.Json2xml(data).to_xml())# get the xml from a json stringdata=readfromstring('{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}')print(json2xml.Json2xml(data).to_xml())# get the data from an URLdata=readfromjson("examples/licht.json")print(json2xml.Json2xml(data).to_xml())

**自定义包装和缩进***

默认情况下,将设置包装器all和缩进2。但是,您可以在代码中这样轻松地更改它:

fromjson2xmlimportjson2xml,readfromurl,readfromstring,readfromjsondata=readfromstring('{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}')print(json2xml.Json2xml(data,wrapper="custom",indent=8).to_xml())

输出这个:

<custom><avatar_url>https://avatars0.githubusercontent.com/u/1?v=4</avatar_url><id>1</id><login>mojombo</login></custom>

方法简单易用,代码内部也有检查退出。 如果任何输入(文件、字符串或api url)返回无效的json。

学分

这个包是用Cookiecutteraudreyr/cookiecutter-pypackage项目模板创建的。

历史记录

3.0.0(2019-02-22)

  • pypi上的第一个版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Android首选项相同getPreference()值的不同数据   字符串如何在Java中连接两个列表中的单词   安卓 Java Socket编程:检测客户端和服务器是否连接   使用JTextField的java无法将值转换为int   在java中,如何在不通过超级构造函数设置的情况下将消息设置为自定义异常类   用于标识属性值的java正则表达式模式   Android中的java不可见谷歌地图   java正确取消启动ExecutorService的JavaFX任务   在非活动java类中使用安卓的融合位置提供程序,并在主活动类中获取经度和纬度   spring为什么我的大摇大摆不能用springboot在java中工作?   java JSF(2.2)ViewScope在Weblogic 12.2.1.2和JDK 8上使用Spring 4.3.7(在Mac OS和Docker Oracle Linux环境上)   java如何用一个按钮提高计时器速度   java如何检查字符是否是元音?   注册表引用了不存在的Java运行时环境安装或运行时已损坏错误   来自ResultSet java的mysql getDateTime   maven LanguageTool Java API是否具有“无用”依赖关系?   twitter api身份验证的java Trycatch问题   java在Apache Struts 1.1中是否可以显式白名单?   安卓致命异常:主java。lang.RuntimeException:被问及未知片段