gpt4 book ai didi

android 网络服务响应 "parse xml to pojo exception"

转载 作者:太空狗 更新时间:2023-10-29 15:16:44 25 4
gpt4 key购买 nike

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

        AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
...
...
String result = (String) httpTransport.responseDump;

我得到了下面给出的 xml 格式的响应 result 字符串,

<?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。 引用: 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;
}
}

最佳答案

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

关于android 网络服务响应 "parse xml to pojo exception",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12095437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com