- 首先引入相关jar包依赖
com.thoughtworks.xstream xstream1.4.10
- 实例xml字符串
000 20 2016-12-05 09:00 14:00 0 0 21 2016-12-05 14:00 18:00 0 0
- 相关实体类
@XStreamAlias("ROOT") public class Resever { private String result; private String errorDesc; @XStreamAlias("SEG_TIME_LIST") private ListsegTimeList; public String getResult() { return result; } public void setResult(String result) { this.result = result; } public String getErrorDesc() { return errorDesc; } public void setErrorDesc(String errorDesc) { this.errorDesc = errorDesc; } public List getSegTimeList() { return segTimeList; } public void setSegTimeList(List segTimeList) { this.segTimeList = segTimeList; } }
@XStreamAlias("SEG_TIME") public class SegTime { private String segId; private String bookDate; private String segStartTime; private String segEndTime; private String bookedCount; private String bookMaxCount; public String getSegId() { return segId; } public void setSegId(String segId) { this.segId = segId; } public String getBookDate() { return bookDate; } public void setBookDate(String bookDate) { this.bookDate = bookDate; } public String getSegStartTime() { return segStartTime; } public void setSegStartTime(String segStartTime) { this.segStartTime = segStartTime; } public String getSegEndTime() { return segEndTime; } public void setSegEndTime(String segEndTime) { this.segEndTime = segEndTime; } public String getBookedCount() { return bookedCount; } public void setBookedCount(String bookedCount) { this.bookedCount = bookedCount; } public String getBookMaxCount() { return bookMaxCount; } public void setBookMaxCount(String bookMaxCount) { this.bookMaxCount = bookMaxCount; } }
- 使用方式
String xml = ""; XStream xstream=new XStream(new DomDriver()); xstream.processAnnotations(Resever.class); // xml 标签与实体类属性名映射 //xstream.aliasField("SEG_TIME_LIST",Resever.class,"segTimeList"); xstream.aliasField("SEG_ID", SegTime.class,"segId"); xstream.aliasField("BOOK_DATE",SegTime.class,"bookDate"); xstream.aliasField("SEG_START_TIME",SegTime.class,"segStartTime"); xstream.aliasField("SEG_END_TIME",SegTime.class,"segEndTime"); xstream.aliasField("BOOKED_COUNT",SegTime.class,"bookedCount"); xstream.aliasField("BOOK_MAX_COUNT",SegTime.class,"bookMaxCount"); Resever resever = (Resever)xstream.fromXML(xml); 000 20 2016-12-05 09:00 14:00 0 0 21 2016-12-05 14:00 18:00 0 0
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)