0

我希望有人可以帮助我,因为这个问题需要很多时间而且我不知道解决方案。thx 提前很多......我尝试调用我的 AXIS2-Webservice,它返回一个像这样的对象:

public class TestObject{

private int zahl = 1;
private String name = "test";
SecondObject sec_object = new SecondObject("eins");
List <SecondObject> obj_list = new ArrayList<SecondObject>();
static SecondObject [] array;

public TestObject(){
    obj_list.add(new SecondObject("zwei"));
    obj_list.add(new SecondObject("drei"));
    array = obj_list.toArray(new SecondObject[2]); }
    //getter & setter

public class SecondObject {

private String wert;

public SecondObject(String wert) {
    this.wert = wert;
}

在 Android 中,我将其称为:

androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();

int count = response.getPropertyCount();
        Log.v(TAG, "count :"+count);
        for (int y = 0; y < count; y++){
            if (response.getProperty(y)instanceof SoapObject){
                SoapObject sobj = (SoapObject) response.getProperty(y);
                Log.v(TAG, "soapOBJ "+sobj);
                Log.v(TAG, "count "+sobj.getPropertyCount());
                if (sobj.getProperty(0)!= null){
                    Log.v(TAG, "!=NULL"+sobj.getProperty(0)+"");
                }   
            }
        }

SoapObject array = (SoapObject) response.getProperty("array");
Log.v(TAG, "array "+array);

我看到很多帖子,它们只调用一个对象数组。在这种情况下,我想调用一个包含对象数组的对象...问题是:数组仅包含一个元素,请参阅此日志:

09-05 14:58:31.120: V/ASYNCTASK(9314): count :7
09-05 14:58:31.120: V/ASYNCTASK(9314): soapOBJ SecondObject{wert=zwei; }
09-05 14:58:31.120: V/ASYNCTASK(9314): count 1
09-05 14:58:31.120: V/ASYNCTASK(9314): !=NULLzwei
09-05 14:58:31.120: V/ASYNCTASK(9314): soapOBJ SecondObject{wert=drei; }
09-05 14:58:31.120: V/ASYNCTASK(9314): count 1
09-05 14:58:31.120: V/ASYNCTASK(9314): !=NULLdrei
09-05 14:58:31.120: V/ASYNCTASK(9314): soapOBJ SecondObject{wert=zwei; }
09-05 14:58:31.120: V/ASYNCTASK(9314): count 1
09-05 14:58:31.120: V/ASYNCTASK(9314): !=NULLzwei
09-05 14:58:31.120: V/ASYNCTASK(9314): soapOBJ SecondObject{wert=drei; }
09-05 14:58:31.120: V/ASYNCTASK(9314): count 1
09-05 14:58:31.120: V/ASYNCTASK(9314): !=NULLdrei
09-05 14:58:31.120: V/ASYNCTASK(9314): soapOBJ SecondObject{wert=eins; }
09-05 14:58:31.120: V/ASYNCTASK(9314): count 1
09-05 14:58:31.120: V/ASYNCTASK(9314): !=NULLeins
09-05 14:58:31.120: V/ASYNCTASK(9314): array SecondObject{wert=zwei; }
4

1 回答 1

0

您可以从顶层获取单个节点,SoapObject如下所示:

SoapObject response = (SoapObject) envelope.getResponse();
String name =  response.getPrimitivePropertySafelyAsString(NODE_NAME_FOR_NAME /* e.g. "name"? */);
int zahl = Integer.parseInt(response.getPrimitivePropertySafelyAsString(NODE_NAME_FOR_ZAHL /* e.g. "zahl"? */));
SoapObject obj_list = (SoapObject) response.getPropertySafely("obj_list");
for (int idx = 0; idx < obj_list.getPropertyCount(); idx++) {
    SoapObject secondObject = (SoapObject) forecastResultsNode.getProperty(idx);

    String wert=  forecastNode.getPrimitivePropertySafelyAsString("wert");
}

如果您可以发布实际 SOAP 响应的片段(以 XML 格式),那就太好了,这样我就可以提供更具体的答案。

可以在此博客文章中找到解析与您描述的结构类似的响应的示例。

于 2012-10-16T01:25:17.043 回答