【发布时间】:2017-09-12 10:07:36
【问题描述】:
我想将 JSON 数组转换为 XML,但在转换过程中会生成无效的 XML 文件:
String str = "{ 'test' : [ {'a' : 'A'},{'b' : 'B'}]}";
JSONObject json = new JSONObject(str);
String xml = XML.toString(json);
我按照Converting JSON to XML in Java中的建议使用了上面的代码
但如果我尝试将 JSON 对象转换为 XML,它会给出无效的 XML(错误:The markup in the document following the root element must be well-formed.),即
<test><a>A</a></test><test><b>B</b></test>
谁能告诉我如何从 JSON 数组中获取有效的 XML 或如何在转换为 XML 时包装 JSON 数组?
提前致谢。
【问题讨论】: