博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
xml转换成java对象
阅读量:5264 次
发布时间:2019-06-14

本文共 2789 字,大约阅读时间需要 9 分钟。

xml直接转换成java对象
Xml格式如下
Success
Success
0
1_8_40_6109_20131226153050_3
java类如下
package com.beisun.mbp.mbp.util.entity;import java.io.Serializable;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlElement;import javax.xml.bind.annotation.XmlRootElement;import javax.xml.bind.annotation.XmlType;import lombok.Getter;import lombok.Setter;@XmlRootElement(name = "ResponseInfo")@XmlType@XmlAccessorType(XmlAccessType.NONE)public class XmlAfrDetect implements Serializable{    private static final long serialVersionUID = 1234567890001L;        @XmlElement(name = "ResCode")    private @Setter    @Getter    String ResCode;        @XmlElement(name = "ResMessage")    private @Setter    @Getter    String ResMessage;        @XmlElement(name = "ErrorNo")    private @Setter    @Getter    String ErrorNo;        @XmlElement(name = "ResultToken")    private @Setter    @Getter    String ResultToken;        @XmlElement(name = "Result")    private @Setter    @Getter    XmlAfrResult Result;        }@XmlRootElement(name = "Result")@XmlType@XmlAccessorType(XmlAccessType.NONE)public class XmlAfrResult implements Serializable{    private static final long serialVersionUID = 1234567890002L;        @XmlElement(name = "Faces")    private @Setter    @Getter    XmlAfrFaces Faces;        @XmlElement(name = "forms")    private @Setter    @Getter    XmlOcrForms forms;}@XmlRootElement(name = "forms")@XmlType@XmlAccessorType(XmlAccessType.NONE)public class XmlOcrForms implements Serializable{            private static final long serialVersionUID = 123456677888990L;        @XmlElement(name = "form")    private @Setter    @Getter    XmlOcrForm form;}@XmlRootElement(name = "form")@XmlType@XmlAccessorType(XmlAccessType.NONE)public class XmlOcrForm implements Serializable{        private static final long serialVersionUID = 12345667788899L;            @XmlAttribute(name = "id")    private @Setter    @Getter    String id;        @XmlAttribute(name = "name")    private @Setter    @Getter    String name;        @XmlAttribute(name = "ver")    private @Setter    @Getter    String ver;            @XmlElement(name = "page")    private @Setter    @Getter    XmlOcrPage page;    }

 

把xml直接转换成对象的代码
import javax.xml.bind.JAXB;//protocolXML是 xml字符串哦StringReader xml = new StringReader(protocolXML);XmlAfrDetect responseInfo =JAXB.unmarshal(xml, XmlAfrDetect.class);

 

转载于:https://www.cnblogs.com/nmdzwps/p/nmamtf.html

你可能感兴趣的文章
普通求素数和线性筛素数
查看>>
PHP截取中英文混合字符
查看>>
【洛谷P1816 忠诚】线段树
查看>>
电子眼抓拍大解密
查看>>
tomcat7的数据库连接池tomcatjdbc的25个优势
查看>>
Html 小插件5 百度搜索代码2
查看>>
java.io.IOException: read failed, socket might closed or timeout, read ret: -1
查看>>
java 常用命令
查看>>
卷积中的参数
查看>>
51nod1076 (边双连通)
查看>>
ViewPager的onPageChangeListener里面的一些方法参数:
查看>>
Linux pipe函数
查看>>
java equals 小记
查看>>
2019春 软件工程实践 助教总结
查看>>
Zerver是一个C#开发的Nginx+PHP+Mysql+memcached+redis绿色集成开发环境
查看>>
多线程实现资源共享的问题学习与总结
查看>>
java实现哈弗曼树
查看>>
程序的静态链接,动态链接和装载 (补充)
查看>>
关于本博客说明
查看>>
线程androidAndroid ConditionVariable的用法
查看>>