我正在尝试通过soap访问webservice。我得到了一个响应,但它的数组格式,我无法获得单个元素。请帮助我从中退出
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME1);
//Use this to add parameters
request.addProperty("CityName",txtFar.getText().toString());
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
/*SoapObject result,obj1,obj2,obj3;
int count;*/
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION1, envelope);
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
if(result != null)
{
//Get the first property and change the label text
Toast.makeText(getApplicationContext(), "before Edt", 500).show();
txtCel.setText(result.getProperty(0).toString());
//txtCel.setText(result.getProperty(0).toString());
Toast.makeText(getApplicationContext(), "After Edt", 500).show();
}
else
{
Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
答案 0 :(得分:0)
我希望这个示例代码有帮助:
SoapObject result = soapConnection.sendRequest(request, METHOD);
List<Pair<Integer, String>> list = new ArrayList<Pair<Integer,String>>();
for(int i=0; i<result.getPropertyCount(); i++) {
SoapObject soapObject = (SoapObject) result.getProperty(i);
int distributorId = Integer.parseInt(soapObject.getPropertyAsString(0));
String distributorName = soapObject.getPropertyAsString(1);
list.add(new Pair<Integer, String>(distributorId, distributorName));
}