Java 元素';结果';也是类中的路径名
我在xml文档下面集成SimpleXml反序列化,但每次都出现异常。不知道确切的原因是什么 但我的代码显示“ElementException” 若我在列表上方注释了@Path(“结果”),那个么控制台将显示valueRequiredException 我该怎么办Java 元素';结果';也是类中的路径名,java,android,simple-framework,Java,Android,Simple Framework,我在xml文档下面集成SimpleXml反序列化,但每次都出现异常。不知道确切的原因是什么 但我的代码显示“ElementException” 若我在列表上方注释了@Path(“结果”),那个么控制台将显示valueRequiredException 我该怎么办 <xten> <status> <return_code>200</return_code> </status> <result
<xten>
<status>
<return_code>200</return_code>
</status>
<results>
<total_count>40</total_count>
<npp>5</npp>
<result type="PRRT" no="1" docid="64458" count="37">
<field name="DISPTEL">11111111111</field>
<field name="UP_CD">65789</field>
</result>
<result type="PRRT" no="1" docid="64458" count="37">
<field name="DISPTEL">11111111111</field>
<field name="UP_CD">65789</field>
</result>
<result type="PRRT" no="1" docid="64458" count="37">
<field name="DISPTEL">11111111111</field>
<field name="UP_CD">65789</field>
</result>
</results>
</xten>
@Root(strict=false)
public class SearchInfosXten {
@Path("results")
@Element(name = "total_count")
private int totalCount;
@Path("results")
@Element(name = "npp")
private int npp;
@ElementList(name = "results", entry = "result")
private List<SearchResult> result;
public int getTotalCount() {
return totalCount;
}
public int getNpp() {
return npp;
}
public List<SearchResult> getResults() {
return result;
}
}
public class SearchResult {
@Attribute(name = "type")
private String type;
@Attribute(name = "no")
private String no;
@Attribute(name = "docid")
private String docId;
@Attribute(name = "count")
private String count;
@ElementList
private List<Item> items;
public String getType() {
return type;
}
public String getNo() {
return no;
}
public String getDocId() {
return docId;
}
public String getCount() {
return count;
}
public List<Item> getItems() {
return items;
}
public class Item {
@Attribute(name = "name")
public String name;
@Text(data=true)
public String text;
}
}
200
40
5.
11111111111
65789
11111111111
65789
11111111111
65789
@Root(strict=false)
公共类搜索信息{
@路径(“结果”)
@元素(name=“总数”)
私人整数总数;
@路径(“结果”)
@元素(名称=“npp”)
私营国际核电站;
@元素列表(name=“results”,entry=“result”)
私有列表结果;
public int getTotalCount(){
返回totalCount;
}
公共int getNpp(){
返回核电站;
}
公共列表getResults(){
返回结果;
}
}
公共类搜索结果{
@属性(name=“type”)
私有字符串类型;
@属性(name=“no”)
私人字符串编号;
@属性(name=“docid”)
私有字符串docId;
@属性(name=“count”)
私有字符串计数;
@元素列表
私人清单项目;
公共字符串getType(){
返回类型;
}
公共字符串getNo(){
返回否;
}
公共字符串getDocId(){
返回docId;
}
公共字符串getCount(){
返回计数;
}
公共列表getItems(){
退货项目;
}
公共类项目{
@属性(name=“name”)
公共字符串名称;
@文本(数据=真)
公共字符串文本;
}
}
我找到了解决方案。尝试使用@ElementList(entry=“result”,inline=true)
请看下面的代码
@Root(strict=false)
public class SearchInfosXten {
@Element(name = "results")
private Results results;
public Results getResults() {
return results;
}
}
@Root(strict = false)
public class Results {
@Element(name = "total_count")
private int totalCount;
@ElementList(entry = "result", inline = true)
private List<Result> result;
public int getTotalCount() {
return totalCount;
}
public List<Result> getResult() {
return result;
}
}
@Root(strict = false)
public class Result {
@Attribute(name = "type")
private String type;
@Attribute(name = "no")
private int no;
@Attribute(name = "docid")
private int docId;
@Attribute(name = "count")
private int count;
@ElementMap(entry = "field", key = "name", attribute = true, inline = true)
private Map<String, String> fields;
public String getType() {
return type;
}
public int getNo() {
return no;
}
public int getDocId() {
return docId;
}
public int getCount() {
return count;
}
public List<Item> getItems() {
return items;
}
public Map<String, String> getFields() {
return fields;
}
}
@Root(strict=false)
公共类搜索信息{
@元素(name=“results”)
私人成果;
公共结果getResults(){
返回结果;
}
}
@Root(strict=false)
公开课成绩{
@元素(name=“总数”)
私人整数总数;
@ElementList(entry=“result”,inline=true)
私有列表结果;
public int getTotalCount(){
返回totalCount;
}
公共列表getResult(){
返回结果;
}
}
@Root(strict=false)
公开课成绩{
@属性(name=“type”)
私有字符串类型;
@属性(name=“no”)
私人互联网号码;
@属性(name=“docid”)
私人文件;
@属性(name=“count”)
私人整数计数;
@ElementMap(entry=“field”,key=“name”,attribute=true,inline=true)
私有地图字段;
公共字符串getType(){
返回类型;
}
公共int getNo(){
返回否;
}
public int getDocId(){
返回docId;
}
public int getCount(){
返回计数;
}
公共列表getItems(){
退货项目;
}
公共映射getFields(){
返回字段;
}
}