Ksoap简单数组android
我正在尝试从返回 Strings 数组的 Web 服务检索数据。 我无法做到这一点,所以我给你一段代码
请帮助我,我快疯了!
public void updateCategories(){
SOAP_ACTION = "http://app.market_helper.com/getCategories";
METHOD_NAME = "getCategories";
Log.i("MESSAGE FROM me", "It's running wtf");
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(
URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
Log.i("message to me",""+response.getPropertyCount());
}catch (Exception e) {
e.printStackTrace();
}
}
我可以从原始类型检索数据,但这有点复杂。 这是网络服务的响应,
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getCategoriesResponse xmlns="http://DefaultNamespace">
<getCategoriesReturn>desktop computers</getCategoriesReturn>
<getCategoriesReturn>laptop computers</getCategoriesReturn>
<getCategoriesReturn>mobile phones</getCategoriesReturn>
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
</getCategoriesResponse>
</soapenv:Body>
</soapenv:Envelope>
提前致谢
I'm trying to retrieve data from web service that returns an array of Strings .
I couldn't do it so I give you a snippet of code
please help me I'm going crazy!
public void updateCategories(){
SOAP_ACTION = "http://app.market_helper.com/getCategories";
METHOD_NAME = "getCategories";
Log.i("MESSAGE FROM me", "It's running wtf");
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(
URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
Log.i("message to me",""+response.getPropertyCount());
}catch (Exception e) {
e.printStackTrace();
}
}
I can retrieve data from primitive types but this is going a little bit complex .
this is the response from the web service
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getCategoriesResponse xmlns="http://DefaultNamespace">
<getCategoriesReturn>desktop computers</getCategoriesReturn>
<getCategoriesReturn>laptop computers</getCategoriesReturn>
<getCategoriesReturn>mobile phones</getCategoriesReturn>
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
<getCategoriesReturn xsi:nil="true" />
</getCategoriesResponse>
</soapenv:Body>
</soapenv:Envelope>
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够使用
response.getProperty(index).toString()
获取字符串值,或者如果需要,response.getPropertyAsString(index)
(索引也可以是替换为属性名称)。要检索所有字符串值,请尝试将它们放入循环中,该循环将字符串添加到列表中。在将属性添加到列表之前,我还要确保该属性不为空。
这对你有用吗?
You should be able to get the string values with
response.getProperty(index).toString()
or if you want,response.getPropertyAsString(index)
(index can also be replaced with the name of the property). To retrieve all string values, try putting them into a loop which adds the strings into a list.I also make sure that the property is not null before adding it into the list.
Does this work for you?
此行:
应更改为:
以使用:
This line:
should be changed to:
to use: