我在解析 KSoap2 的复杂响应时遇到问题。
我的响应 XML 文件是:
<Word>breadth</Word>
<Definitions>
<Definition>
<Word>breadth</Word>
<Dictionary>
<Id>gcide</Id>
<Name>The Collaborative International Dictionary of English v.0.44</Name>
</Dictionary>
<WordDefinition>Breadth \Breadth\ (br[e^]dth)</WordDefinition>
</Definition>
<Definition>
<Word>breadth</Word>
<Dictionary>
<Id>moby-thes</Id>
<Name>Moby Thesaurus II by Grady Ward, 1.0</Name>
</Dictionary>
<WordDefinition>87 Moby Thesaurus words for "breadth": </WordDefinition>
</Definition>
</Definitions>
我的班级文件是:
public class MainActivity extends Activity {
private static final String SOAP_ACTION = "http://services.aonaware.com/webservices/Define";
private static final String NAMESPACE = "http://services.aonaware.com/webservices/";
private static final String METHOD_NAME = "Define";
private static final String URL = "http://services.aonaware.com/DictService/DictService.asmx";
int n=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
PropertyInfo pi1=new PropertyInfo();
pi1.setName("word");
pi1.setValue("breadth");
pi1.setType(String.class);
request.addProperty(pi1);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet=true;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport =new HttpTransportSE(URL);
try{
androidHttpTransport.call(SOAP_ACTION, soapEnvelope);
SoapObject resultAns = (SoapObject)soapEnvelope.getResponse();
System.out.println("Full ans: "+resultAns);
}
catch(Exception e){
e.printStackTrace();
}
}
我在 LogCat 上的输出是:
Here 1: anyType{Word=breadth; Definitions=anyType{Definition=anyType{Word=breadth; Dictionary=anyType{Id=gcide; Name=The Collaborative International Dictionary of English v.0.44; }; WordDefinition=Breadth \Breadth\ (br[e^]dth)
; }; Definition=anyType{Word=breadth; Dictionary=anyType{Id=moby-thes; Name=Moby Thesaurus II by Grady Ward, 1.0; }; WordDefinition=87 Moby Thesaurus words for "breadth":
; }; }; }
我从 2 天开始一直在搜索.. 仍然无法解析它。我是 ksoap2 的新手。所以我不知道解析复杂对象的正确方法。那么你能告诉我你是如何从中获得价值的吗?
编辑:我没有连接问题,我只想知道从 Xml 节点获取数据,问题是这个 XML 在另一个节点内有节点。所以我认为实际的努力是从那条soupEnvelope.getResopnse()
线开始的。帮助Lz!