重新调整complexType对象时,SoapObject Result将anyType {}作为值返回

时间:2012-09-09 06:56:32

标签: android android-ksoap2

我在我的Android应用程序中调用了一个Web服务&方法是getGramaNiladhariData(), 我得到的结果是SoapObject。

result = (SoapObject) envelope.bodyIn;  Log.d("WS", String.valueOf(result));

这就是我为 String.valueOf(结果)

所获得的

getGramaNiladhariDataResponse {getGramaNiladhariDataResult = anyType的{gnName = anyType的{};地址= anyType的{}; workingDays = anyType的{}; gnDivision = anyType的{}; contactNumber = anyType的{}; }; }

这里我调用的方法返回一个complexType对象,由5个属性组成。 正如我在互联网上发现的那样,我无法获得soap对象作为返回complexType对象的webservice方法的结果。如果是这样,我应该如何获取值。

我想要解决的是为什么我得到anyType {},作为值,而不是实际值。 任何帮助将不胜感激

4 个答案:

答案 0 :(得分:5)

回答太迟了。但是我和其他认为有用的人,

通过执行String.valueOf(result),您将打印身体的全部内容。但是为了使用参数获取您的值,首先您需要点击以更正SoapObject

我不知道是否有任何简单的方法可以找到正确的SoapObject,但仍然可以这样做,一旦你得到了正确的SoapObject,那么你就完成了。在下面找到如何找到正确的SoapObject

首先,您需要检查第一个SoapObject中的参数数量,

result.getPropertyCount();

你会得到更少的数量,因为这是第一个封面,

然后,打印并查看哪个param为您提供了核心信息,

result.getProperty(0);
result.getProperty(1);
etc ...

找到正确的参数后,抓住SoapObject。像这样,

SoapObject result2 = (SoapObject) result.getProperty(0);

然后检查此对象的计数。并执行与上述相同的操作,直到获得正确的SoapObject

找到最后一个SoapObject后,它会像这样打印而没有无用的字符串,

anyType{gnName = Prasad; address = Address of the person; ; workingDays = 5; gnDivision = California; contactNumber = 0123456789}

现在你可以像这样继续使用这个对象,

SoapObject result3 = (SoapObject) result2.getProperty(5);
Log.v("Name : ", result3.getProperty("gnName").toString());

您将获得DDMS中的输出,如下所示,

Name : Prasad

我想这会对你有帮助,如果你有任何进一步的问题,请告诉我。

答案 1 :(得分:1)

我制作自己的代码我刚刚完成它我想与你分享它可能会帮助一些

我只与一张桌子一起工作,这对我有用 我将尝试解释步骤

    try {
        // Invole web service
        androidHttpTransport.call(SOAP_ACTION + "mywebservicecall", envelope);
        // Get the response

        SoapObject resultsString = (SoapObject) envelope.getResponse();
          //resultsString looks like this ==> anyType{schema=anyType{element=anyType{complexType=anyType{choice=anyT....etc
          //here i found some complex in getproperty(0) so i not need it
          //then i make Object1 that contain datatable from my database getproperty(1)


        SoapObject Object1 = (SoapObject) resultsString.getProperty(1);
           //object1 look like this ==> anyType{NewDataSet=anyType{Table1=anyType{ID_CAT=1; CAT_V_N=ma 
           //here my table1 i wanna to fitch the NewDataSet

        SoapObject tables = (SoapObject) Object1.getProperty(0);  //NewDataset
           //tables object now looks like this  ==> anyType{Table1=anyType{ID_CAT=1;CAT_N ...etc

           //now i wanna loop in my table to get columns valus it will be tablesObject properties depend on iteration to get row by row
        for (int i = 0; i < tables.getPropertyCount(); i++) {
            SoapObject Objecttable = (SoapObject) tables.getProperty(i); 
           System.out.println("ID_CAT = " + Objecttable.getProperty("ID_CAT").toString());
           System.out.println("CAT_N= " +Objecttable.getProperty("CAT_N").toString()); 
        }

    } catch (Exception e) {
        e.printStackTrace(); 
           System.out.println("ID_CAT = 0 ");
           System.out.println("CAT_N = None");
    } 

最后一段代码解释一个表

现在我刚刚结束的是如何控制多表

我也会解释它

        SoapObject resultsString = (SoapObject) envelope.getResponse(); 
        // the same
        SoapObject Object1 = (SoapObject) resultsString.getProperty(1); 
        // the same
        SoapObject tables = (SoapObject) Object1.getProperty(0); 
        // the same


        // the same
        for(int i = 0; i < tables.getPropertyCount(); i++){
            SoapObject Objecttable = (SoapObject) (SoapObject) tables.getProperty(i);

            try{ 

//tables.toString().substring(8,tables.toString().indexOf("=")).equals("Table1")
   // here i was try to get the name of the table to hundel it but i fount my table name in attribute id 
   // it not came as table name like if my table that comming from database is hi
   //the first row will be attrib=>id=>hi1 and sec row will be hi2 
   //the first row will be attrib=>rowOrder=>0 and sec row will be 1 
                    if(Objecttable.getAttribute("id").equals("Table1"+(Integer.valueOf(Objecttable.getAttribute("rowOrder").toString())+1))){
// so Objecttable.getAttribute("id") will be ( "Table11" ) in first row
//Objecttable.getAttribute("rowOrder").toString() ==> will be 0

//Integer.valueOf(Objecttable.getAttribute("rowOrder").toString())+1) well be 1 for first row of this table

// so Objecttable.getAttribute("id").equals("Table1"+(Integer.valueOf(Objecttable.getAttribute("rowOrder").toString())+1)) will be true 
/**
then i can loop and fitch data like single table 
*/
                }

                if(Objecttable.getAttribute("id").equals("Table2"+(Integer.valueOf(Objecttable.getAttribute("rowOrder").toString())+1))){

                }
            }catch (Exception e) {
            }

希望你们好运好运

答案 2 :(得分:0)

当您从Web服务获取空值时,会出现

anytype {}。首先插入一些数据,然后尝试从Web服务获取数据。

答案 3 :(得分:-1)

我以前遇到过这个问题。我解决了它。我以前遇到过这个问题。我解决了它。我似乎花了很多时间来找到解决这个问题的方法。我的项目是它的工作。我创建了Web Service .Net Object Array。我希望这会对你有所帮助。

        //.................................
        SoapObject requestx = new SoapObject(NAMESPACE, METHOD_NAME);

        SoapSerializationEnvelope envelopex = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelopex.dotNet = true;
        envelopex.setOutputSoapObject(requestx);
        HttpTransportSE httpTransportx = new HttpTransportSE(URL);          

        try  {                    
            httpTransportx.call(SOAP_ACTION, envelopex);
            SoapObject responsex = (SoapObject)envelopex.getResponse(); // not envelopex.bodyIn;

             int i=0;
             int RCount=responsex.getPropertyCount();
             int[] tbIDArray = new int[RCount+1];
             int[] iMonthAarray = new int[RCount+1];
             int[] iYearAarray = new int[RCount+1];
             String[] sDetailAarray = new String[RCount+1];

             for (i = 0; i < RCount; i++) {
                 Object property = responsex.getProperty(i);
                 if (property instanceof SoapObject) {
                     SoapObject info = (SoapObject) property;
                     String tbID = info.getProperty("tbID").toString();
                     String iMonth = info.getProperty("iMonth").toString();
                     String iYear = info.getProperty("iYear").toString();
                     String sDetail = info.getProperty("sDetail").toString();

                    tbIDArray[i] =Integer.valueOf(tbID);
                    iMonthAarray[i] =Integer.valueOf(iMonth);
                    iYearAarray[i] =Integer.valueOf(iYear);
                    sDetailAarray[i] =sDetail;
                 }//if (property instanceof SoapObject) {
             }//for (i = 0; i < RCount; i++) {


        }  catch (Exception exception)   {
            MsgBox1(exception.toString() , "Error");
        }