如何解析Andorid Web服务的XML响应
问题描述:
嗨,大家好我是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();
}
}
答
也许你有一个困难时期,因为响应不是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
Duplicate http://stackoverflow.com/questions/17968111/parsing-soapobject-responst-in-android – 2014-09-20 15:38:41