gpt4 book ai didi

android - 如何在android中解析一个SoapObject

转载 作者:行者123 更新时间:2023-11-29 14:01:36 25 4
gpt4 key购买 nike

我正在为应用程序使用网络服务以从外部服务器获取数据。我能够连接到服务器,发送我的 SOAP 请求并能够将数据作为 SoapObject 返回到我的 android 类。在这里,我无法解析此 SoapObject 以检索来自 Web 服务的值(作为字符串)。我的代码在这里:

 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
mInflater = (LayoutInflater)getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
System.out.println("Entered "+getClass().getSimpleName());
//Calling the web service to get the documents list
callService("getDocumentsList","http://wservice.friedmaggy.com/getDocumentsList");

-- 我已经创建了调用 web 服务的 callService 方法。:

public void callService(String operation, String soapaction)
{
try {
String SOAP_ACTION = soapaction;
String OPERATION_NAME = operation;
String WSDL_TARGET_NAMESPACE = getString(R.string.targetNamespace);
String SOAP_ADDRESS = getString(R.string.soapAddress);
SoapObject request = new SoapObject(
WSDL_TARGET_NAMESPACE, OPERATION_NAME);
System.out.println("SOAP_ACTION "+SOAP_ACTION);
System.out.println("OPERATION_NAME "+OPERATION_NAME);
System.out.println("WSDL_TARGET_NAMESPACE "+WSDL_TARGET_NAMESPACE);
System.out.println("SOAP_ADDRESS "+SOAP_ADDRESS);
// System.out.println("SOAP_ACTION "+SOAP_ACTION);

PropertyInfo propInfo = new PropertyInfo();

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);

HttpTransportSE httpTransport = new HttpTransportSE(
SOAP_ADDRESS);
envelope.setOutputSoapObject(request);

httpTransport.call(SOAP_ACTION, envelope);

SoapObject response = (SoapObject) envelope.bodyIn;


if(response.getPropertyCount()>0){
data=new StringBuilder();

for (int i = 0; i < response.getPropertyCount(); i++) {

Course c = new Course((SoapObject) response.getProperty(i));

courseList.add(c);

}

for (Course c : courseList) {

data.append("CourseName :" + c.getName());

results.add(c.getName());
}

-- 如上所示,我将整个响应对象传递给另一个 bean 类以获取值。(Course c = new Course((SoapObject) response.getProperty(i));)

你能帮我解析这个响应对象来获取所需的字符串值吗?

最佳答案

androidHttpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();

Vector<SoapObject> res= null;

if (response instanceof SoapObject) {
res = new Vector();
res.add((SoapObject) response);
} else if (response instanceof Vector) {
res = (Vector<SoapObject>) response;
}

for(SoapObject so1: res){
//retrieve String here from soap object using this
so1.getProperty(0).toString();
//then so1.getProperty(1).toString and likewise
}

关于android - 如何在android中解析一个SoapObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9249099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com