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

时间:2011-12-16 11:14:42

标签: android web-services ksoap

如果我尝试使用(String) response.getProperty(0);检索第一个数组,但它返回了一个完整的字符串。

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

}

我在矢量类型

中收到了回复
[Client{UserId=93; nickName=ladies; }, Client{UserId=94; nickName=ABCD; }]

Here is the image of return response

我尝试了很多方法,但我不能以任何方式取回成功吗?

2 个答案:

答案 0 :(得分:0)

使用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) {

        }

答案 1 :(得分:0)

解析所需部分的字符串。使用String Class的regex或Substring函数。