简体   繁体   English

如何从Android中的KSOAP Web服务检索对象数组?

[英]How to retrieve array of objects as a result from KSOAP web service in Android?

If I am trying to retrieve first array using (String) response.getProperty(0); 如果我试图使用(String) response.getProperty(0);检索第一个数组(String) response.getProperty(0); but it was returning me a full string. 但它给了我一个完整的字符串。

**Here is the code of webservice calling**

public static Object getResponse(String methodName, String actionName, LinkedHashMap<String, String> valueStrings)
{
    SoapObject soapObject = new SoapObject(LetUsClickAPIConstants.COMMON_NAMESPACE, methodName);
    Object response = null;
    for (Map.Entry<String, String> mapKeys : valueStrings.entrySet())
    {
        soapObject.addProperty(mapKeys.getKey(), mapKeys.getValue());
    }
    final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = false;
    envelope.setOutputSoapObject(soapObject);
    final AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(LetUsClickAPIConstants.COMMON_URL);
    try
    {
        androidHttpTransport.call(actionName, envelope);
        response = envelope.getResponse();
        Log.d("Response ", response.toString());
    } catch (final IOException e)
    {
        Log.d("Exception", "" + e);
    } catch (final XmlPullParserException e)
    {

        Log.d("Exception", "" + e);
    }
    return response;

}

I got an response in Vector type 我在Vector类型中得到了回复

[Client{UserId=93; nickName=ladies; }, Client{UserId=94; nickName=ABCD; }]

这是返回响应的图像

I have tried many ways but I am not success to retrieve in any way? 我尝试了很多方法但是我不能以任何方式检索成功吗?

Use FolloWing code.. 使用FolloWing代码..

Soapresponse = Ksoap.CallService("SOAP_METHOD_NAME);

        try {
            if (Soapresponse != null) {
                SoapObject Soapresult = (SoapObject) Soapresponse
                        .getProperty(0);

                if (Soapresult != null) {
                    SoapObject Dataset = (SoapObject) Soapresult
                            .getProperty(1);
                    if (Dataset != null) {
                        SoapObject Table = (SoapObject) Dataset
                                .getProperty(0);
                        if (Table != null) {
                            UserId= new String[Table.getPropertyCount()];
                            nickName= new String[Table
                                    .getPropertyCount()];

                            for (int i = 0; i < total_News; i++) {
                                SoapObject row = (SoapObject) Table
                                        .getProperty(i);

                                UserId[i] = row.getProperty("UserId")
                                        .toString();
                                nickName[i] = row.getProperty(
                                        "nickName").toString();
                                                                }
                        }
                    }
                }
            }

        } catch (NullPointerException f) {

        } catch (ClassCastException d) {

        }

Parse the string for the parts you want. 解析所需部分的字符串。 Using regex or Substring function of String Class. 使用String Class的regex或Substring函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM