如何将响应从Web服务转换或解析为String数组?

时间:2014-02-06 12:02:57

标签: java android web-services arrays

我从webservice返回一个String []数组。在我的Android应用程序中,我得到了这样的回复:

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,60000);

androidHttpTransport.call(SOAP_ACTION, envelope);

Vector<?> response = (Vector<?>) envelope.getResponse();

String sTripResponse = response.toString();
System.out.println("My Response: \n" + response.toString());

这是响应的字符串:

02-06 12:58:23.729: I/System.out(8239): [1#1040#2014-02-04#2014-02-04#16:50:17#16:55:47#Ranshofen#Braunau am Inn#0#292608#0.383901696, 2#1040#2014-02-04#2014-02-05#16:55:47#07:54:26#Braunau am Inn#Ranshofen#0#390144#0.512259072]

我想把这个响应放在一个字符串数组中,但我不知道该怎么做。

任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

试试这可能有助于你

String sTripResponse = response.toString();
    String finalString = sTripResponse.substring(1, sTripResponse.length() - 1);
    String[] arr = finalString.split("#");
    for (int i = 0; i < arr.length; i++) {
        System.out.println("" + arr[i]);
    }

答案 1 :(得分:0)

String[] oK = Response.replace("[", "").replace("]", "").split(",");