我使用Gson-xml库将xml强制转换为对象。这是我的xml:
<GetSentMessageListResponse xmlns="http://ICAN.ir/x/mWebServices/">
<GetSentMessageListResult>
<Message>
<ID>2620</ID>
<Subject>test</Subject>
<Description>&lt;div style=&quot;font-family:Tahoma;font-size:20pt&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;</Description>
<SentDate>7/10/2018 5:04:40 PM</SentDate>
<Receivers>
<Receiver>
<RoleID>393</RoleID>
<UserID>717</UserID>
<UserName>f</UserName>
<NativeID />
</Receiver>
<Receiver>
<RoleID>786</RoleID>
<UserID>5</UserID>
<UserName>mm</UserName>
<NativeID />
</Receiver>
</Receivers>
<MessageFiles />
</Message>
</GetSentMessageListResult>
<strErrorMsg />
</GetSentMessageListResponse>
和打击是我的课:
public class StructureMessageListResultOP {
private StructureMessageList GetRecieveMessageListResult;
private StructureMessageList GetSentMessageListResult;
private String StrErrorMsg;
public StructureMessageList getGetRecieveMessageListResult() {
return GetRecieveMessageListResult;
}
public void setGetRecieveMessageListResult(StructureMessageList getRecieveMessageListResult) {
GetRecieveMessageListResult = getRecieveMessageListResult;
}
public StructureMessageList getGetSentMessageListResult() {
return GetSentMessageListResult;
}
public void setGetSentMessageListResult(StructureMessageList getSentMessageListResult) {
GetSentMessageListResult = getSentMessageListResult;
}
public String getStrErrorMsg() {
return StrErrorMsg;
}
public void setStrErrorMsg(String strErrorMsg) {
StrErrorMsg = strErrorMsg;
}
//____________________________________________________
public class StructureMessageList {
List<StructureMessageListBodyOP> Message;
public List<StructureMessageListBodyOP> getMessage() {
return Message;
}
public void setMessage(List<StructureMessageListBodyOP> message) {
Message = message;
}
}
}
public class StructureMessageListBodyOP {
private int ID;
private String Subject;
private String Description;
private String SentDate;
StructureReceiverList Receivers;
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public String getSubject() {
return Subject;
}
public void setSubject(String subject) {
Subject = subject;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
public String getSentDate() {
return SentDate;
}
public void setSentDate(String sentDate) {
SentDate = sentDate;
}
public StructureReceiverList getReceivers() {
return Receivers;
}
public void setReceivers(StructureReceiverList receivers) {
Receivers = receivers;
}
//-------------------------- **ReceiverList** -------------------------------
public class StructureReceiverList {
List<StructureReceiverOP> Receiver;
public List<StructureReceiverOP> getReceiver() {
return Receiver;
}
public void setReceiver(List<StructureReceiverOP> receiver) {
Receiver = receiver;
}
}
//___________________________________________________________________________
}
公共类StructureReceiverOP {
private int RoleID;
private int UserID;
private String UserName;
public int getRoleID() {
return RoleID;
}
public void setRoleID(int roleID) {
RoleID = roleID;
}
public int getUserID() {
return UserID;
}
public void setUserID(int userID) {
UserID = userID;
}
public String getUserName() {
return UserName;
}
public void setUserName(String userName) {
UserName = userName;
}
}
我的问题是Gson-xml无法转换inerList并在写入时
List<StructureReceiverOP> Receiver;
设置错误,无法投射。
请帮我,我累了。
我还是尝试过,但是没有。 我认为该库非常强大,但事实并非如此。 如果您知道可以使用此功能的更好的库,请告诉我。提及
答案 0 :(得分:0)
我尝试了很多次,最后找到了另一个使用java核心的库。 我使用了Simple-xml。您可以从Link
中使用它答案 1 :(得分:0)
您可以将xml转换为json并使用gson库。