6

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

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

这就是我得到的 String.valueOf(result)

getGramaNiladhariDataResponse{getGramaNiladhariDataResult=anyType{gnName=anyType{}; 地址=anyType{}; 工作天=任何类型{};gnDivision=anyType{}; 联系人号码=任何类型{};}; }

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

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

4

4 回答 4

6

已经来不及回答了。但仅供参考和其他认为这很有用的人,

通过做String.valueOf(result)你正在打印正文的全部内容。但为了使用参数获取您的值,首先您需要点击正确的SoapObject.

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

首先,您需要首先检查参数的数量SoapObject

result.getPropertyCount();

由于这是第一个封面,因此您将获得更少的计数,

然后,打印并查看哪个参数为您提供了正确的详细信息,

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

我想这会对您有所帮助,如果您还有其他问题,请告诉我。

于 2012-11-01T09:50:27.820 回答
2

当您从 Web 服务获取空值时出现 anytype{}。首先插入一些数据,然后尝试从 Web 服务获取数据。

于 2014-08-05T04:42:26.907 回答
2

我制作自己的代码我刚刚完成现在我想与你分享它可能会有所帮助

我只在一张桌子上工作,那是我的工作,我将尝试解释步骤

    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) {
            }

希望这对你们来说很清楚,祝你好运

于 2018-05-06T15:36:54.560 回答
-1

我以前遇到过这个问题。我解决了它。我以前遇到过这个问题。我解决了它。我似乎花了很多时间来寻找解决这个问题的方法。我的项目它的工作。我创建 Web 服务 .Net 对象数组。我希望这能帮到您。

        //.................................
        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");
        }
于 2013-03-31T19:57:41.010 回答