标签:io ar os sp java on bs as new
String xxml = "<listhospital>"+ "<count>153</count>"+ "<hospital>"+ "<id>12</id>"+ "<name>北京大学第一医院</name>"+ "</hospital>"+ "<hospital>"+ "<id>13</id>"+ "<name>北京大学第一医院</name>"+ "</hospital>"+ "</listhospital>"; XStream xstream=new XStream(new DomDriver()); //注意:不是new Xstream(); 否则报错: xstream.processAnnotations(Result.class); Result person=(Result)xstream.fromXML(xxml); System.out.println(person.toString());
注解
@XStreamAlias("listhospital") public class Result{ @XStreamAlias("count") private int count; @XStreamImplicit(itemFieldName="hospital") private List<Hospital> listHospital; 简略 get set }
public class Hospital { @XStreamAlias("id") private int id; @XStreamAlias("name") private String name; 简略 get set
标签:io ar os sp java on bs as new
原文地址:http://my.oschina.net/u/587105/blog/346386