我的android应用程序发送一个web服务请求,并从xml中的web服务获取响应,并使用JSON中的嵌入数据。我将它保存在一个字符串中。现在我不知道如何从这个字符串中获取JSON数据。如何从服务器的XML响应中获取JSON?
System.setProperty("http.keepAlive", "false");
// request parameters
HttpParams params = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 15000);
// set parameter
HttpProtocolParams.setUseExpectContinue(httpClient.getParams(), true);
// POST the envelope
HttpPost httppost = new HttpPost(url);
// add headers
httppost.setHeader("SOAPAction", soapAction);
httppost.setHeader("Content-Type", "text/xml; charset=utf-8");
// httppost.setHeader("Content-Length",
// String.valueOf(requestEnvelope.length()));
httppost.setHeader("SOAPAction", "http://tempuri.org/"
+ methodName);
// String responseString = "";
try {
// the entity holds the request
HttpEntity entity = new StringEntity(requestEnvelope);
httppost.setEntity(entity);
HttpResponse response = httpClient.execute(httppost);
String result = EntityUtils.toString(response.getEntity());
这是从服务器得到的结果字符串中的响应。
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ValidatePassCodeResponse xmlns="http://tempuri.org/">
<ValidatePassCodeResult>
[{"ID":1929,"Headline":"Test News","Detail":"","SubmitDate":"1/17/2012 12:08:04 PM"}]
</ValidatePassCodeResult>
</ValidatePassCodeResponse>
</soap:Body>
</soap:Envelope>
在此先感谢。
...和答案是什么?如果你写下你发现的内容,下一个这个问题的读者可能会受益。 – 2012-01-19 13:18:13