我正在开发一个android应用程序,在该应用程序中,我使用SOAP从一个.NET web服务中获得一些对象。我没有问题得到我的目标。我使用ksoap2-android来处理请求。
我需要一种很好的方法来将这个对象的类型解析为一个互补的Java对象。有人知道怎么做吗?
它由简单类型和其他由简单类型组成的对象组成。
我现在知道的唯一方法是:
String[] types = o.toString().split(";");然后解析字符串数组。有什么更方便的方法吗?
好的,举个例子是个好主意,下面是我的目标之一:
SessionConfigurations=anyType{Client_SessionConfiguration=anyType{ID=2;{Success=true;UserMessage=anyType{};TechnicalMessage=anyType{};IntValue=0;DoubleValue=0;DateTimeValue=0001-01-01T00:00;AgeGroups=anyType{};Name=Skoleklasser;};Client_SessionConfiguration=anyType{ID=3;Name=Virksomheder;};Client_SessionConfiguration=anyType{ID=4;Name=Gæster;};}
发布于 2011-03-03 14:43:22
我从android中调用了很多web服务。我扩展了org.xml.sax.helpers.DefaultHandler类来处理响应。
public class BaseXMLResponseHandler extends DefaultHandler {
StringBuffer accumulator = new StringBuffer();
@Override
public void characters(char[] buffer, int start, int length)
throws SAXException {
accumulator.append(buffer, start, length);
}
}然后只需实现这些方法
public void endElement(String uri, String localName, String qName) throws SAXException
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException例如:
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
accumulator.setLength(0); // Ready to accumulate new text
}
List<String> testElements = new ArrayList<String>();
public void endElement(String uri, String localName, String qName) throws SAXException
{
if (localName.equals("testelement")) {
testElements.add(accumulator.toString());
}
}
List<String> getElements() {
return testElements;
}https://stackoverflow.com/questions/5182049
复制相似问题