xstream将返回的xml解析为bean,出错,急急急
 public class BulletinResponse {

    private String transId;

    private String processTime;

    private String cpId;

    private String curPage;

    private String pageCount;

    private String returnCode;

    private String content;
    private List<Info> infoList;

    public String getTransId() {
        return transId;
    }

    public void setTransId(String transId) {
        this.transId = transId;
    }

    public String getProcessTime() {
        return processTime;
    }

    public void setProcessTime(String processTime) {
        this.processTime = processTime;
    }

    public String getCpId() {
        return cpId;
    }

    public void setCpId(String cpId) {
        this.cpId = cpId;
    }

    public String getCurPage() {
        return curPage;
    }

    public void setCurPage(String curPage) {
        this.curPage = curPage;
    }

    public String getPageCount() {
        return pageCount;
    }

    public void setPageCount(String pageCount) {
        this.pageCount = pageCount;
    }

    public String getReturnCode() {
        return returnCode;
    }

    public void setReturnCode(String returnCode) {
        this.returnCode = returnCode;
    }

    public List<Info> getInfoList() {
        return infoList;
    }

    public void setInfoList(List<Info> infoList) {
        this.infoList = infoList;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

}
 public class Info {

    private String contentCode;

    private String gameName;

    private String osVersion;

    private String monthlyType;

    private String lastupdate;

    private String status;

    private String sourceType;

    private String approveStatus;

    public String getGameName() {
        return gameName;
    }

    public void setGameName(String gameName) {
        this.gameName = gameName;
    }

    public String getOsVersion() {
        return osVersion;
    }

    public void setOsVersion(String osVersion) {
        this.osVersion = osVersion;
    }

    public String getMonthlyType() {
        return monthlyType;
    }

    public void setMonthlyType(String monthlyType) {
        this.monthlyType = monthlyType;
    }

    public String getLastupdate() {
        return lastupdate;
    }

    public void setLastupdate(String lastupdate) {
        this.lastupdate = lastupdate;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getSourceType() {
        return sourceType;
    }

    public void setSourceType(String sourceType) {
        this.sourceType = sourceType;
    }

    public String getApproveStatus() {
        return approveStatus;
    }

    public void setApproveStatus(String approveStatus) {
        this.approveStatus = approveStatus;
    }

    public String getContentCode() {
        return contentCode;
    }

    public void setContentCode(String contentCode) {
        this.contentCode = contentCode;
    }


}
 <?xml version="1.0" encoding="UTF-8"?>
<notifyRsp>
     <transId>1447296864744</transId>
     <processTime>20151112105424</processTime>
     <cpId>710791</cpId>
     <curPage>1</curPage>
     <pageCount>181</pageCount>
     <returnCode>0000</returnCode>
         <content>
             <contentCode>006011863000</contentCode>
             <gameName>安卓单机112_001</gameName>
             <monthlyType></monthlyType>
             <osVersion>1</osVersion>
             <status>8</status>
             <sourceType>2</sourceType>
             <approveStatus>1,3|2,3|3,3|4,3|5,3|6,3|7,3|8,3</approveStatus>
             <lastupdate>Nov 12, 2015 10:40:54 AM</lastupdate>
         </content>
         <content>
             <contentCode>006011767000</contentCode>
             <gameName>20151110yxshi单机_android</gameName>
             <monthlyType></monthlyType>
             <osVersion>1</osVersion>
             <status>8</status>
             <sourceType>2</sourceType>
             <approveStatus>1,3|2,1|3,1|4,1|5,1|6,1|7,2|8,3</approveStatus>
             <lastupdate>Nov 10, 2015 3:06:43 PM</lastupdate>
         </content>
         <content>
             <contentCode>006011769000</contentCode>
             <gameName>20151110yxshi网游IOS</gameName>
             <monthlyType></monthlyType>
             <osVersion>2</osVersion>
             <status>8</status>
             <sourceType>2</sourceType>
             <approveStatus>1,3|2,1|3,1|4,1|5,1|6,1|7,1|8,3|9,1</approveStatus>
             <lastupdate>Nov 10, 2015 3:06:08 PM</lastupdate>
         </content>
         <content>
             <contentCode>006011768000</contentCode>
             <gameName></gameName>
             <monthlyType></monthlyType>
             <osVersion>1</osVersion>
             <status>0</status>
             <sourceType>2</sourceType>
             <approveStatus></approveStatus>
             <lastupdate>Nov 10, 2015 2:54:20 PM</lastupdate>
         </content>
         <content>
             <contentCode>006011765000</contentCode>
             <gameName></gameName>
             <monthlyType></monthlyType>
             <osVersion>1</osVersion>
             <status>0</status>
             <sourceType>2</sourceType>
             <approveStatus></approveStatus>
             <lastupdate>Nov 10, 2015 2:19:00 PM</lastupdate>
         </content>
</notifyRsp>

1个回答

列出个实体类和xml文件内容是几个意思???起码也把处理过程贴出来吧?

大体思路是这样,你可以通过XML文件内容做XML解析,解析后对每个节点做校验,看节点名称是否是你的实体类中定义的参数。

最后,根据set参数名运用反射,就能把xml文件的信息,转换为实体类对象了。。。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问