English 中文(简体)
Ksoap简单的阵列和roid
原标题:Ksoap simple array android

I m trying to retrieve data from web service that returns an array of Strings . I couldn t do it so I give you a snippet of code
please help me I m going crazy!

public void updateCategories(){
        SOAP_ACTION = "http://app.market_helper.com/getCategories";
        METHOD_NAME = "getCategories";
        Log.i("MESSAGE FROM me", "It s running wtf");
        try {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(
                    URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject)envelope.getResponse();
        Log.i("message to me",""+response.getPropertyCount());
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

I can retrieve data from primitive types but this is going a little bit complex . this is the response from the web service

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getCategoriesResponse xmlns="http://DefaultNamespace">
  <getCategoriesReturn>desktop computers</getCategoriesReturn> 
  <getCategoriesReturn>laptop computers</getCategoriesReturn> 
  <getCategoriesReturn>mobile phones</getCategoriesReturn> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  <getCategoriesReturn xsi:nil="true" /> 
  </getCategoriesResponse>
  </soapenv:Body>
  </soapenv:Envelope> 

预先感谢

问题回答

您应当能够以<代码>response.getProperty(index.toString()或如果你愿意,response.getPropertyAsString(index)(索引也可以财产名称取代)。 为了收回所有扼杀性价值,试图将它们变成一个把扼杀物列入清单的漏洞。

List<String> categories = new ArrayList<String>();
int count = response.getPropertyCount();

for(int i = 0; i < count; i++) {
    if(response.getProperty(i) != null)
        categories.add(response.getPropertyAsString(i));
}

我也确保,在将财产列入清单之前,财产不会无效。

你们是否做了这项工作?

本条:

SoapObject response = (SoapObject)envelope.getResponse();

应当改为:

SoapObject response = (SoapObject)envelope.bodyIn;

使用:

response.getProperty(Index);




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签