我正在使用.Net Web服务使用ksoap2从Android中的服务器获取数据。
我可以使用以下代码将数据获取到SoapObject

    public class MainActivity extends Activity {
        private static final String _SOAP_ACTION = "http://tempuri.org/getUserDetails";
        private static final String _METHOD_NAME = "getUserDetails";
        private static final String _NAMESPACE = "http://tempuri.org/";
        private static final String _URL = "http://sush19.in/myservice/myservice.asmx";
        SoapObject _response;

        public void getUserInfo() {
            SoapObject request = new SoapObject(_NAMESPACE, _METHOD_NAME);
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet=true;
            envelope.setOutputSoapObject(request);
            try
            {
                AndroidHttpTransport aht=new AndroidHttpTransport(_URL);
                aht.call(_SOAP_ACTION,envelope);
                _response=(SoapObject)envelope.getResponse();
                String s1 = (String)_response.getProperty(0);
                String s2 = (String)_response.getProperty(1);
                String s3 = (String)_response.getProperty(2);
                String s4 = (String)_response.getProperty(3);
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
                Toast.makeText(getBaseContext(), "Oops..."+ex, Toast.LENGTH_LONG).show();
            }
        }
    }

我可以使用上面的_response.getProperty获得每个值,而我得到的值是正确的anyType{anyType=user1; anyType=pswd1; anyType=user2; anyType=pswd2; anyType=user3; anyType=pswd3; anyType=user4; anyType=pswd4; anyType=user5; anyType=pswd5; anyType=user6; anyType=pswd6; }我要获取的数据是用户名和密码。
我想将其存储在数组中以进行进一步的操作,例如将其存储到Sqlite DB中。我的数据库表有两列
username    userPassword

我希望以上数据采用以下格式:
user1   pswd1
user2   pswd2
user3   pswd3
user4   pswd4
user5   pswd5
user6   pswd6

这样很容易找到带有相应密码的用户名。如何将SoapObject转换为Array

最佳答案

步骤1:创建与您的.net服务器返回的bean类相同的类
步骤2:解析数据并创建该bean类的对象
步骤3:添加到数组
做你想做的事

关于android - 如何将SoapObject数据存储到数组?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20234938/

10-10 17:09