u010831487 2016-03-25 02:50 采纳率: 0%
浏览 2803

jax-ws调用webService返回结果为json,使用拼装soap调用返回信息转义了

返回json:{"loginName":"admin1","msg":"return success","ret":"0"}
以下是调用方法:
public static String callWS(String SOAPUrl, String body) throws Exception {
URL url = new URL(SOAPUrl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
String httpContent = body;
byte[] b = httpContent.getBytes("utf-8");
httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
httpConn.setRequestProperty("SOAPAction", "");
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
OutputStream out = httpConn.getOutputStream();
out.write(b);
out.close();
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream(),"utf-8");
BufferedReader in = new BufferedReader(isr);
String result = "";
String inputLine;
while ((inputLine = in.readLine()) != null) {
result = result + inputLine;
}
in.close();
return result;
}

    返回信息如下:

<?xml version='1.0' encoding='UTF-8'?>


{"loginName":"admin1","msg":"return success","ret":"0"}
/ns2:singleLoginExResponse
/S:Body
/S:Envelope
返回的json信息中,引号被转义了,如何才能不装义,通过我的调用方法得到:
<?xml version='1.0' encoding='UTF-8'?>



{"loginName":"admin1","msg":"return success","ret":"0"}
/ns2:singleLoginExResponse
/S:Body
/S:Envelope
这样的返回内容。(由于公司要求,必须采用这种调用方法callWS调webService,并且返回json字符串)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突