本文主要是介绍Android xml转object之XStream的坑!坑!坑!,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
牛逼的领导指出返回数据要xml格式,弱弱的安卓程序猿也无力回天啊!只能硬着头皮干!
第一步:xml解析有没有类似Gson/fastjson类似的工具呢?找了半天终于找到了今天的主角XStream。
先贴出要解析的xml
<?xml version="1.0" encoding="UTF-8" ?>
<name title="三角波"><Wave tag="V1" seq="0"><Samples name="张三"> 0X0000, 0X0000, 0X0000 </Samples><WaveAnnotations/></Wave><Wave tag="V2" seq="0"><Samples name="李四"> 0X0000, 0X0000, 0X0000 </Samples><WaveAnnotations/></Wave>
</name>
对应的实体类: TestModel.java
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamImplicit;import java.util.List;@XStreamAlias("name")
public class TestModel {@XStreamAsAttributeprivate String title;/*** tag : V1* seq : 0* Samples : 0X0000, 0X0000, 0X0000* WaveAnnotations :*/@XStreamImplicit(itemFieldName = "Wave")private List<WaveBean> Wave;public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public List<WaveBean> getWave() {return Wave;}public void setWave(List<WaveBean> Wave) {this.Wave = Wave;}@XStreamAlias("Wave")public static class WaveBean {@XStreamAsAttributeprivate String tag;@XStreamAsAttributeprivate int seq;@XStreamAsAttributeprivate SamplesBean Samples;@XStreamAsAttributeprivate WaveAnnotationsBean WaveAnnotations;public String getTag() {return tag;}public void setTag(String tag) {this.tag = tag;}public int getSeq() {return seq;}public void setSeq(int seq) {this.seq =
这篇关于Android xml转object之XStream的坑!坑!坑!的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!