0

Strings の配列を返す Web サービスからデータを取得しようとしています。できなかったので、コードのスニペットを提供します。
助けてください。私は夢中になっています。

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();
        }
    }

プリミティブ型からデータを取得できますが、これは少し複雑です。これは Web サービスからの応答です

<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> 

前もって感謝します

4

2 に答える 2

2

response.getProperty(index).toString()または必要に応じて、文字列値を取得できるはずですresponse.getPropertyAsString(index)(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));
}

また、プロパティをリストに追加する前に、プロパティが null でないことを確認します。

これはうまくいきますか?

于 2012-01-13T15:05:50.927 に答える
1

この行:

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

次のように変更する必要があります。

SoapObject response = (SoapObject)envelope.bodyIn;

使用する:

response.getProperty(Index);
于 2012-09-18T19:27:50.463 に答える