gpt4 book ai didi

web-services - 如何使用 Ksoap 2 从 Web 服务 (.NET) 方法获取 List 到应用程序 android
转载 作者:行者123 更新时间:2023-12-04 05:48:43 26 4
gpt4 key购买 nike

假设在visual studio中我有一个方法:

    [WebMethod]
public List<PhongTro> GetAllLodgingHousesByAddress(string address)
{
return db.GetAllLodgingHousesByAddress(address);
}

如何在android中将返回数据类型转换为ArrayList?

最佳答案

您可以按如下方式使用此代码模板:

public ArrayList<PhongTro> getPhongTros() {
ArrayList<PhongTro> arrPhongTro = new ArrayList<PhongTro>();

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;

try {
androidHttpTransport.call(SOAP_ACTION, envelope);

/** contains all arrPhongTro objects */
SoapObject response = (SoapObject) envelope.getResponse();

/** lists property count */
final int intPropertyCount = response.getPropertyCount();

/** loop */
for (int i = 0; i < intPropertyCount; i++) {
/** temp SoapObject */
SoapObject responseChild = (SoapObject) response.getProperty(i);

/** temp PhongTro object */
PhongTro tempObj = new PhongTro();

if (responseChild.hasProperty("att0")) {
tempObj.setAtt0(responseChild.getPropertyAsString("att0"));
}
if (responseChild.hasProperty("att1")) {
tempObj.setAtt1(responseChild.getPropertyAsString("att1"));
}

if (responseChild.hasProperty("att2")) {
tempObj.setAtt2(responseChild.getPropertyAsString("att2"));
}

if (responseChild.hasProperty("att3")) {
tempObj.setAtt3(responseChild.getPropertyAsString("att3"));
}

if (responseChild.hasProperty("att4")) {
tempObj.setAtt4(responseChild.getPropertyAsString("att4"));
}

/** Adding temp PhongTro object to list */
arrPhongTro.add(tempObj);
}

} catch (Exception e) {
e.printStackTrace();

/** if an error handled arrPhongTro setting null */
arrPhongTro = null;
}

/** returning list */
return arrPhongTro;
}

关于web-services - 如何使用 Ksoap 2 从 Web 服务 (.NET) 方法获取 List<object> 到应用程序 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10360009/

26 4 0