Java 正在从服务器获取soap对象响应。如何在ANDROID中解析soap对象
您好,这是我第一次使用soap,因此我遇到了一些问题,无法解析Java 正在从服务器获取soap对象响应。如何在ANDROID中解析soap对象,java,android,soap,ksoap2,android-ksoap2,Java,Android,Soap,Ksoap2,Android Ksoap2,您好,这是我第一次使用soap,因此我遇到了一些问题,无法解析 我正在使用(ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar)这个 所以这里我想为这五个字段和 将其存储到Arraylist或hashmap中。请给我一些关于此soap对象的建议 解析 catalogCategoryTree{category_id=1; parent_id=0; name=Root; position=1; level=0; children=Arra
我正在使用(ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar)这个 所以这里我想为这五个字段和 将其存储到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
您可以为每个对象(在您的案例3中)执行此操作。Ksoap提供了一个更有用的方法getPropertyCount(),它告诉您响应中对象的编号。
kSOAP提供了以下非常有用的示例链接,我建议您仔细阅读。
尝试下面的代码,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();
}
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();
}