2014-09-20 88 views
0

嗨,大家好我是Ksoap的新手。我在android中的Web服務上做了一些工作,但現在我無法瞭解如何解析Web Service的XML響應請幫助我。如何解析Andorid Web服務的XML響應

的XML在響應

anyType 
{ 
schema=anyType 
{ 
element=anyType 
{ 
complexType=anyType 
{ 
choice=anyType 
{ 
element=anyType 
{ 
complexType=anyType 
{ 
sequence=anyType 
{ 
element=anyType{}; 
element=anyType{}; 
element=anyType{}; 
element=anyType{}; 
element=anyType{}; 
element=anyType{}; 
}; }; }; }; }; }; }; 

diffgram=anyType 
{ 
MobileApp=anyType 
{ 
tbl_Vehicles=anyType 
{ 
ID=1; 
PlateNumber=95459; 
Latitude=25.167330; 
Longitude=55.237670; 
Status=Driving; 
Location=Sheikh Zayed Rd. Dubai; 
}; 

tbl_Vehicles=anyType 
{ 
ID=2; 
PlateNumber=45926; 
Latitude=25.127791; 
Longitude=55.114626; 
Status=Parked; 
Location=Alpha Tours, Palm Jumeirah, Dubai; 
}; 
}; 
}; 
} 

我的代碼如下

public void getVehicleList() 
{ 
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);  

request.addProperty("UserID", id); 

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 

envelope.setOutputSoapObject(request); 
envelope.dotNet = true; 

try 
{ 
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
    androidHttpTransport.call(SOAP_ACTION_LOGIN, envelope); 


    if (envelope.bodyIn instanceof SoapFault) 
    { 
     String str = ((SoapFault) envelope.bodyIn).faultstring; 
     Log.i("SoapFault", str); 
     showDialog("Error", "Their Is Some Problem In Server Response"); 
    } 
    else 
    { 
     SoapObject response = (SoapObject)envelope.bodyIn; 

     Log.d("Veh ID 8", "Result = " + response.toString()); 
    } 
} 
catch (Exception e) 
{ 
     e.printStackTrace(); 
} 

}

+0

Duplicate http://stackoverflow.com/questions/17968111/parsing-soapobject-responst-in-android – 2014-09-20 15:38:41

回答

0

也許你有一個困難時期,因爲響應不是XML?

+0

是的,你是對的。我通過互聯網搜索它,然後發現沒有正確格式化的JSON。你有任何解決方案。 – 2014-09-20 17:55:36

+0

如果您有權訪問JSON數據作爲字符串,只需執行以下操作:JSONObject o = new JSONObject(data);然後通過JSONObject API開始訪問數據(如o.getString(「schema」);) – 2014-09-20 20:07:02