English 中文(简体)
2. 结 反应
原标题:Parsing ksoap2 response

我使用一种千分之分,与SOAP网络服务用户和roid客户进行沟通。 跳跃小组做了大量的工作,但问题在于,没有任何很好的例子说明如何在不同方面加以利用。 例如,我收到以下数据:

anyType{
    StatusSetting=anyType{Id=1; Name=Til afskrivning; LocationId=1; Editable=true; Default=true; Transcribed=false; }; 
    StatusSetting=anyType{Id=2; Name=Afskrevet; LocationId=1; Editable=false; Default=false; Transcribed=true; }; 
    ...
}

It s a complex object, or rather a collection of StatusSetting objects. When I try to get a property of SoapObject it s only 1 property with all that data as a string. It can t be parsed as json too. Unbelievable that nobody met same problem regarding to popularity android is gaining. Would be very cool to know if somebody solved this issue and how. Thanks.

最佳回答

http://seesharpgears.blogspot.com/201010/ksoap-android-web-service-tutorial-with.html” rel=“nofollow” 我看到无数小时的偷盗。 希望这一座标

问题回答

www.un.org/Depts/DGACM/index_spanish.htm 例如,您的答复:。

anyType
{
  FOO_DEALS=anyType
  {
       CATEGORY_LIST=anyType
       {
         CATEGORY=Books; 
         CATEGORY_URL=books_chennai; 
         CATEGORY_ICON=http://deals.foo.com/common/images/books.png; 
         CATEGORY_COUNT=1045; 
         TYPE=1; 
         SUPERTAG=Books; 
       };
       CATEGORY_LIST=anyType
       {
           CATEGORY=Cameras;
           CATEGORY_URL=cameras_chennai;
           CATEGORY_ICON=http://deals.foo.com/common/images/cameras.png; 
           CATEGORY_COUNT=152; 
           SUPERTAG=Cameras; 
           TYPE=1; 
       }; 
   }; 
 }

www.un.org/Depts/DGACM/index_spanish.htm 要求和教职:

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
           // Add the input required by web service
           request.addProperty("city","chennai");
           request.addProperty("key","10000");

           SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(SoapEnvelope.VER11);
           envelope.setOutputSoapObject(request);

           // Make the soap call.
           androidHttpTransport.call(SOAP_ACTION, envelope);

           // Get the SoapResult from the envelope body.
           resultRequestSOAP = (SoapObject) envelope.bodyIn;


           System.out.println("********Response : "+resultRequestSOAP.toString());

           SoapObject root = (SoapObject) resultRequestSOAP.getProperty(0);
           SoapObject s_deals = (SoapObject) root.getProperty("FOO_DEALS");

           StringBuilder stringBuilder = new StringBuilder();

           System.out.println("********Count : "+ s_deals.getPropertyCount());

           for (int i = 0; i < s_deals.getPropertyCount(); i++) 
           {
               Object property = s_deals.getProperty(i);
               if (property instanceof SoapObject)
               {
                   SoapObject category_list = (SoapObject) property;
                   String CATEGORY = category_list.getProperty("CATEGORY").toString();
                   String CATEGORY_URL = category_list.getProperty("CATEGORY_URL").toString();
                   String CATEGORY_ICON = category_list.getProperty("CATEGORY_ICON").toString();
                   String CATEGORY_COUNT = category_list.getProperty("CATEGORY_COUNT").toString();
                   String SUPERTAG = category_list.getProperty("SUPERTAG").toString();
                   String TYPE = category_list.getProperty("TYPE").toString();
                   stringBuilder.append
                   (
                        "Row value of: " +(i+1)+"
"+
                        "Category: "+CATEGORY+"
"+
                        "Category URL: "+CATEGORY_URL+"
"+
                        "Category_Icon: "+CATEGORY_ICON+"
"+
                        "Category_Count: "+CATEGORY_COUNT+"
"+
                        "SuperTag: "+SUPERTAG+"
"+
                        "Type: "+TYPE+"
"+
                        "******************************"
                   );                   
                   stringBuilder.append("
");
               }
           }
SoapObject countryDetails = (SoapObject)envelope.getResponse();
System.out.println(countryDetails.toString());

ArrayList list = new ArrayList(countryDetails.getPropertyCount());
lv_arr = new String[countryDetails.getPropertyCount()];
for (int i = 0; i < countryDetails.getPropertyCount(); i++) {
    Object property = countryDetails.getProperty(i);
    if (property instanceof SoapObject) {
        SoapObject countryObj = (SoapObject) property;
        String countryName = countryObj.getProperty("countryName").toString();
        list.add(countryName );
    }
}

希望能发挥作用

我的项目发挥了作用。 希望这一 he。

        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");
        }

JSON格式非常舒适。 我写了一部简单的法典,将SOAP V1的对策改为:

public static String soapStrToJson(String input)
{
    String output;

    output = input;
    output = output.replace("key=", """);
    output = output.replace("; value=", "":");
    output = output.replace("; };",",");
    output = output.replace("item=anyType{","");
    output = output.replace("Map","");
    output = output.replace(",}","}");
    output = output.replace(", }"," }");
    output = output.replace("null","0");

    Pattern pattern = Pattern.compile(":(.*?),");
    Matcher matcher = pattern.matcher(output);

    List<String> wordsToReplace = new ArrayList();
    while (matcher.find())
    {
        String str = matcher.group(0);
        if(str.contains("{") || str.contains("["))
            continue;

        str = str.replace(":", "");
        str = str.replace(",", "");

        if(str.matches("^-?\d+$"))
            continue;

        System.out.println("-->" + str);
        wordsToReplace.add(str);
    }

    for(String str : wordsToReplace)
    {
        output = output.replace(":"+str+",", ":""+str+"",");
    }
    return output;
}

该职能用于:

parseCategoryJSON( new JSONObject( soapStrToJson( env.getResponse().toString() ) ) )

<>说明:我没有使用env. . . . . . .In SoapObject.

这可能不是所有应对措施的完美转化者,因此可以修改《力量》。 根据您的要求,替换和配置材料。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签