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条回答

    报告相同问题?

    悬赏问题

    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波
    • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
    • ¥15 钢筋实图交点识别,机器视觉代码
    • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
    • ¥50 400g qsfp 光模块iphy方案
    • ¥15 两块ADC0804用proteus仿真时,出现异常
    • ¥15 关于风控系统,如何去选择