Problem description
Recently in the attempt to do a development, the use of network communication this piece. There are several questions:
1android client has got Weibservice play Soapobject object But how to parse it into the type of data I need?
XML files obtained from Web pages
<?xml version= "1.0" encoding= "Utf-8"?>
-<user_info>
<USER_NO>adminbb</USER_NO>
<USER_NAME>admin</USER_NAME>
<PASSWORD>e10adc3949ba59abbe56e057f20f883e</PASSWORD>
<ROLE_ID>732</ROLE_ID>
<telephone/>
<email/>
<remark/>
<CREATER>admin</CREATER>
<CREATED_TIME>2005/5/8 0:00:00</created_time>
<MODIFIER>adminbb</MODIFIER>
<LAST_MODIFIED>2012/2/17 10:01:50</last_modified>
<INI_LON>108.9418</INI_LON>
<INI_LAT>34.2640</INI_LAT>
<LAST_LOGIN_TIME>2012/1/9 14:12:04</last_login_time>
<STATUS>1</STATUS>
<dead_line_time>2020/12/31 23:59:59</dead_line_time>
<LAST_LOGIN_IP>36.40.67.173</LAST_LOGIN_IP>
<IS_MANAGER>1</IS_MANAGER>
<GROUP_ID>707</GROUP_ID>
</user_info>
Android above calls the webservice to get the Soapobject ToString () after it looks like this
GETNAMEINFORESPONSE{GETNAMEINFORESULT=ANYTYPE{USER_INFO=ANYTYPE{USER_NO=ADMINBB; User_name=admin; password=e10adc3949ba59abbe56e057f20f883e; role_id=732; telephone=anytype{}; email=anytype{}; remark=anytype{}; Creater=admin; Created_time=2005-5-8 0:00:00; MODIFIER=ADMINBB; LAST_MODIFIED=2012-2-17 10:01:50; ini_lon=108.9418; ini_lat=34.2640; Last_login_time=2012-1-9 14:12:04; Status=1; Dead_line_time=2020-12-31 23:59:59; last_login_ip=36.40.67.173; Is_manager=1; group_id=707; }; }; }
Can you get a DataTable-like data directly to C #.
How can I use the Ksoap class to get a standard XML file and then call Android's own parsing library parsing? Can I only call WebService with the Post get method to get XML? Solutions 1
Get the Soapobject object and loop through each field inside
for (int i=0;i<soapobject.getpropertycount (); i++) {
Soapobject soapchilds = (soapobject) soapobject.getproperty (i);
System.out.println (Soapchilds.getproperty ("User_no"). toString ());
System.out.println (Soapchilds.getproperty ("user_name"). toString ());
.
.
.
} Solution 2
Yes, on the penthouse.
You can debug while looking at the data obtained is not the corresponding solution 3
If you are developing both ends of your own, it is recommended to use JSON, fast, small size, analytic gray often easy!
Server: result = Jsonconvert.serializeobject (OBJCET);//Start serialization
Client:
Gsonbuilder gsonb = new Gsonbuilder ();//The date expression in JSON has no way to convert directly to our date type, so we need to register a date's deserialization class separately. Datedeserializer ds = new Datedeserializer ();//The Gsonbuilder method is specified separately for the Date type of the deserialization method Gsonb.registertypeadapter (Date.class, DS); Type T = new typetoken<linkedlist< your data type, and web-side consistent >> () {}.gettype (); Gson Gson = Gsonb.create ();//parse JSON data into object if (!result.equals ("1")) {//result is the string you get, T is the type to convert resultlist = Gson.fromjson (result, t);}
Solutions 4
Reference 2 Floor Weicheng_android's reply:
get the Soapobject object and loop through each field inside
for (int i=0;i <soapobject.getpropertycount (); i++) {
Soapobject soapchilds = (soapobject) soapobject.getproperty (i);
System.out.println (Soapchilds.getpro
...
Since the use of soapobject, then use its standard solution, one layer to take, until the right!
Webservce in Android to get Soapobject data parsing problem