3
我想訪問android中的soap webservices。android webservice響應「解析XML到pojo異常」
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
...
...
String result = (String) httpTransport.responseDump;
我得到的迴應結果字符串作爲下面給出的XML格式,
<?xml version="1.0" encoding="UTF-8"?>
<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>
<sampleResponse xmlns="http://impl.test.com">
<sampleReturn>
<clientNameList>
<clientNameList>
<clientID>1</clientID>
</clientNameList>
<clientNameList>
<clientID>2</clientID>
</clientNameList>
</clientNameList>
<message>SUCCESS</message>
</sampleReturn>
</sampleResponse>
</soapenv:Body>
</soapenv:Envelope>
使用簡單XML序列化(簡單的XML-2.6.6.jar)解析這個XML到的POJO。 編號:here
Persister persister = new Persister();
UserResponse userResponse = persister.read(UserResponse.class, result);
現在,我得到的異常,因爲
Element 'Body' does not have a match in class com.test.UserResponse at line 1
更多代碼信息here
我怎樣才能解決這個問題?
UserResponse.java(POJO類)
public class UserResponse {
private String message = null;
private Client[] clientNameList = null;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void setClientNameList(Client[] clientNameList) {
this.clientNameList = clientNameList;
}
public Client[] getClientNameList() {
return clientNameList;
}
}
和Client.java
public class Client {
private int clientID;
public void setClientID(int clientID) {
this.clientID = clientID;
}
public int getClientID() {
return clientID;
}
}
請向我們展示您創建的POJO類。 –
我在問題中添加了我的POJO類 – Manoj