在 Java 中将 JSON 转换为 XML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14850466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert JSON to XML in Java
提问by Jon
Are there any .jars out there that can be used to convert JSON to XML? A lot of the answers on SO contain dead links or involve complex configuration.
是否有任何 .jar 文件可用于将 JSON 转换为 XML?SO上的很多答案都包含死链接或涉及复杂的配置。
Ideally it would be nice just to include a jar in my existing project that currently converts XML to JSON. I just need it the other way around to be complete.
理想情况下,在我目前将 XML 转换为 JSON 的现有项目中包含一个 jar 会很好。我只需要反过来就可以完成。
回答by Christophe Roussy
Have a look at this article:
看看这篇文章:
From the article:
从文章:
Use json-lib, a library which adds JSON support to any Java program. json-lib provides an XMLSerializer which can be used to output XML from a JSON object.
使用 json-lib,这是一个为任何 Java 程序添加 JSON 支持的库。json-lib 提供了一个 XMLSerializer,可用于从 JSON 对象输出 XML。
回答by Samuel EUSTACHI
I would recommand to convert JSON to java classes (using GSON for instance), then the java classes to XML (possibly using JAXB). Then you'll have a comprehensive way to manage how you want to perform the conversion.
我建议将 JSON 转换为 java 类(例如使用 GSON),然后将 java 类转换为 XML(可能使用 JAXB)。然后,您将拥有一种全面的方法来管理您希望如何执行转换。