[英]Android - How to deserialize xml containing list of objects using Simple api
[英]Android How to deserialize xml containing list of objects using Simple api
需要使用簡單的API反序列化對對象的xml響應。 當我反序列化對象時,出現異常:org.simpleframework.xml.core.ElementException:元素'Transducer'在類java.lang.Object的第1行沒有匹配項
會發現我做錯了什么的線索,或者使用復雜對象反序列化內聯列表的工作示例。
謝謝。
附件是我的對象的簡化示例:
我的xml:
<?xml version="1.0"?>
<Profile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Transducers>
<Transducer Value="0" Name="nDate" Unit="" ChineseName="時間" IsVisibility="true" Formatter="yyyyMMddHHmm" MessageLength="12" />
<Transducer Value="0" Name="EnvirTemp" Unit="℃" ChineseName="環溫" IsVisibility="true" Formatter="0.0" MessageLength="4" />
<Transducer Value="0" Name="EnvirHumid" Unit="%RH" ChineseName="環濕" IsVisibility="true" Formatter="0.0" MessageLength="4" />
</Transducers>
<MMX>
<Transducers>
<Transducer Value="0" Name="aa" Unit="" ChineseName="a" IsVisibility="true" Formatter="0.0" MessageLength="4" />
<Transducer Value="0" Name="bb" Unit="" ChineseName="a" IsVisibility="true" Formatter="0.0" MessageLength="4" />
</Transducers>
</MMX>
</Profile>
我的對象:
@Root
public class Profile {
@ElementList(entry="Transducer")
public List<Transducer> Transducers;
@ElementList
public List<List<Transducer>> MMX;
}
@Element
public class Transducer {
@Attribute
public double Value;
@Attribute
public String Name;
@Attribute
public String Unit;
@Attribute
public String ChineseName;
@Attribute
public boolean IsVisibility;
@Attribute
public String Formatter;
@Attribute
public String MessageLength;
}
我已經為每個屬性添加了private,setter和getter,並通過寫入序列化了
<profile>
<CreateDate>2015-3-25</CreateDate>
<Id>1</Id>
<Name>pc4</Name>
<RecorderId>00000</RecorderId>
<Transducers class="java.util.ArrayList">
<Transducer ChineseName="溫度" Formatter="0.0" Unit="C" MessageLength="4" Name="Temperature1" IsVisibility="true" Value="0.0"/>
<Transducer ChineseName="溫度2" Formatter="0.0" Unit="C" MessageLength="4" Name="Temperature2" IsVisibility="true" Value="0.0"/>
</Transducers>
</profile>
我從my.xml中反擊,得到了異常
org.simpleframework.xml.core.ElementException:元素'Transducer'在類java.lang.Object中的第1行沒有匹配項
您是否嘗試過將自己的屬性設為私有,並為每個屬性創建getter和setter?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.