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

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!