3

我正在尝试访问 android 中的肥皂网络服务。

        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 序列化 (simple-xml-2.6.6.jar) 将此 xml 解析为 Pojo。参考: 这里

        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

在此处获取更多代码信息

我怎样才能解决这个问题?

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;
    }
}
4

1 回答 1

0

你的回复有问题。您一个接一个地得到<clientNameList>两次,这可能会导致您在解析 XML 时出现问题。所以,最好相应地改变你的反应。

于 2012-08-24T04:43:26.560 回答