java - 从服务器获取 soap 对象响应。如何在 android 中解析 soap 对象

标签 java android soap ksoap2 android-ksoap2

嗨,这是我第一次使用 soap,所以我遇到了一些问题,我无法解析
SOAP 对象。我正在使用 (ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar) 这个 soap.librery.so 在这里我想为这五个字段创建单独的 Bean 类,并且 将它存储到 Arraylist 或 hashmap 中。请给我一些关于这个 soap 对象的建议 解析。

catalogCategoryTree{category_id=1; parent_id=0; name=Root; position=1; level=0; 
children=ArrayOfCatalogCategoryEntities{item=catalogCategoryEntity{category_id=3; 
parent_id=1; name=Root Catalog; is_active=1; position=3; level=1; 
children=ArrayOfCatalogCategoryEntities{item=catalogCategoryEntity{category_id=10; 
parent_id=3; name=Furniture; is_active=1; position=10; level=2; 
children=ArrayOfCatalogCategoryEntities{item=catalogCategoryEntity{category_id=23; 
parent_id=10; name=Bedroom; is_active=1; position=1; level=3; 
children=ArrayOfCatalogCategoryEntities{}; }; item=catalogCategoryEntity{category_id=22;  
parent_id=10; name=Living Room; is_active=1; position=23; level=3;  
children=ArrayOfCatalogCategoryEntities{}; }; }; }; 
item=catalogCategoryEntity{category_id=13; parent_id=3; name=Electronics; is_active=1;  
position=13; level=2; 
children=ArrayOfCatalogCategoryEntities{item=catalogCategoryEntity{category_id=8; 
parent_id=13; name=Cell Phones; is_active=1; position=8; level=3; 
children=ArrayOfCatalogCategoryEntities{}; }; item=catalogCategoryEntity{category_id=15; 
parent_id=13; name=Computers; is_active=1; position=9; level=3; 
children=ArrayOfCatalogCategoryEntities{item=catalogCategoryEntity{category_id=27; 
parent_id=15; name=Build Your Own; is_active=1; position=1; level=4; 
children=ArrayOfCatalogCategoryEntities{}; }; item=catalogCategoryEntity{category_id=28; 
parent_id=15; name=Laptops; is_active=1; position=2; level=4; 
children=ArrayOfCatalogCategoryEntities{}; }; item=catalogCategoryEntity{category_id=29; 
parent_id=13; name=Hard Drives; is_active=1; position=3; level=4; 
children=ArrayOfCatalogCategoryEntities{}; }; item=catalogCategoryEntity{category_id=30; 
parent_id=13; name=Monitors; is_active=1; position=4; level=4; 
children=ArrayOfCatalogCategoryEntities{}; }; item=catalogCategoryEntity{category_id=31; 
parent_id=13; name=RAM / Memory; is_active=1; position=5; level=4; 
children=ArrayOfCatalogCategoryEntities{}; }; item=catalogCategoryEntity{category_id=32; 
parent_id=13; name=Cases; is_active=1; position=6; level=4; 
children=ArrayOfCatalogCategoryEntities{}; }; item=catalogCategoryEntity{category_id=33; 
parent_id=13; name=Processors; is_active=1; position=7; level=4; 
children=ArrayOfCatalogCategoryEntities{}; }; item=catalogCategoryEntity{category_id=34; 
parent_id=13; name=Peripherals; is_active=1; position=8; level=4; 
children=ArrayOfCatalogCategoryEntities{}; }; }; }; 
item=catalogCategoryEntity{category_id=12; parent_id=13; name=Cameras; is_active=1; 
position=13; level=3; 
children=ArrayOfCatalogCategoryEntities{item=catalogCategoryEntity{category_id=25; 
parent_id=12; name=Accessories; is_active=1; position=25; level=4; 
children=ArrayOfCatalogCategoryEntities{}; }; item=catalogCategoryEntity{category_id=26; 
parent_id=12; name=Digital Cameras; is_active=1; position=26; level=4; 
children=ArrayOfCatalogCategoryEntities{}; }; }; }; }; }; 
item=catalogCategoryEntity{category_id=18; parent_id=3; name=Apparel; is_active=1; 
position=14; level=2;  
children=ArrayOfCatalogCategoryEntities{item=catalogCategoryEntity{category_id=4; 
parent_id=18; name=Shirts; is_active=1; position=4; level=3; 
children=ArrayOfCatalogCategoryEntities{}; }; item=catalogCategoryEntity{category_id=5; 
parent_id=18; name=Shoes; is_active=1; position=5; level=3; 
children=ArrayOfCatalogCategoryEntities{item=catalogCategoryEntity{category_id=16;
parent_id=5; name=Mens; is_active=1; position=16; level=4; 
children=ArrayOfCatalogCategoryEntities{}; }; item=catalogCategoryEntity{category_id=17; 
parent_id=5; name=Womens; is_active=1; position=17; level=4; 
children=ArrayOfCatalogCategoryEntities{}; }; }; }; 
item=catalogCategoryEntity{category_id=19; parent_id=18; name=Hoodies; is_active=1; 
position=19; level=3; children=ArrayOfCatalogCategoryEntities{}; }; 
item=catalogCategoryEntity{category_id=24; parent_id=18; name=Pants; is_active=0; 
position=24; level=3; children=ArrayOfCatalogCategoryEntities{}; }; }; }; 
item=catalogCategoryEntity{category_id=20; parent_id=3; name=Household Items; is_active=0; 
position=20; level=2

最佳答案

试试下面的代码,androidHttpTransport 是 HttpTransportSE 对象。然后您将获得正常的 xml 响应并使用任何解析器(如 sax 或 pull 解析器)解析它。

     String response = androidHttpTransport.responseDump

下面给出了我的完整代码,请尝试进行必要的更改..

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

    try {
        HttpTransportSE androidHttpTransport = new HttpTransportSE("url");
        androidHttpTransport.debug = true;
        SoapObject soapObject = (SoapObject) envelope.bodyOut;
        //Log.e("soap request->", "" + soapObject.toString());
        androidHttpTransport.call(soap_Action, envelope);
        String response = androidHttpTransport.responseDump;
        Log.e("response dump->",""+response);
        inputStream = IOUtils.toInputStream(response);
    } catch (Exception e) {
        e.printStackTrace();

    }

关于java - 从服务器获取 soap 对象响应。如何在 android 中解析 soap 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25867178/

相关文章:

android - 使用 Push Sharp 的谷歌云消息传递

android - 是否可以为android的viewpager设置透明

php - Magento soap api catalog_product.list 分页

linux - SOAP:无法分配请求的地址

javascript - 将任意 JavaScript 代码存储到字符串变量中

Java - 创建具有给定范围的 IntStream,然后使用映射函数随机化每个元素

机器人 : open chrome custom tab from fragment

web-services - 如何测试存在时间滞后的 Web 服务?

java - 我的 Java 应用程序的这个对象模型可以改进吗?

java - JDBC资源的正确使用方法