2 u010831487 u010831487 于 2016.03.25 10:50 提问

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字符串)

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!