【发布时间】:2020-04-15 09:40:39
【问题描述】:
我想将 JSON 响应转换为基于 SOAP 的 XML 响应(使用 underscore-java)。
import com.github.underscore.lodash.U;
public class JsonToXml {
public static void main(String[] args) {
String json = "[{\"id\":\"1\",\"name\":\"Bratislava\",\"population\":\"432000\"},{\"id\":\"2\",\"name\":\"Budapest\",\"population\":\"1759000\"},{\"id\":\"3\",\"name\":\"Prague\",\"population\":\"1280000\"},{\"id\":\"4\",\"name\":\"Warsaw\",\"population\":\"1748000\"},{\"id\":\"5\",\"name\":\"Los Angeles\",\"population\":\"3971000\"},{\"id\":\"6\",\"name\":\"New York\",\"population\":\"8550000\"},{\"id\":\"7\",\"name\":\"Edinburgh\",\"population\":\"464000\"},{\"id\":\"8\",\"name\":\"Berlin\",\"population\":\"3671000\"}]";
String jsonToXml = U.jsonToXml(json);
System.out.println(jsonToXml);
}
}
在将 JSON 转换为 XML 时,我们如何添加以下内容以响应 XML?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
【问题讨论】:
标签: java json xml underscore-java