3 回答
TA贡献1788条经验 获得超4个赞
Underscore-java库具有静态方法U.jsonToXml(jsonstring)。我是该项目的维护者。现场例子
import com.github.underscore.lodash.U;
public class MyClass {
public static void main(String args[]) {
String json = "{\"name\":\"JSON\",\"integer\":1,\"double\":2.0,\"boolean\":true,\"nested\":{\"id\":42},\"array\":[1,2,3]}";
System.out.println(json);
String xml = U.jsonToXml(json);
System.out.println(xml);
}
}
输出:
{"name":"JSON","integer":1,"double":2.0,"boolean":true,"nested":{"id":42},"array":[1,2,3]}
<?xml version="1.0" encoding="UTF-8"?>
<root>
<name>JSON</name>
<integer number="true">1</integer>
<double number="true">2.0</double>
<boolean boolean="true">true</boolean>
<nested>
<id number="true">42</id>
</nested>
<array number="true">1</array>
<array number="true">2</array>
<array number="true">3</array>
</root>
添加回答
举报