【问题标题】:No field for implicit collection error in xstreamxstream 中没有隐式收集错误的字段
【发布时间】:2013-01-18 01:59:43
【问题描述】:

我一直在尝试使用 XStream 来转换 XML(它是来自 flash 前端的字符串格式,我可以完全控制 xml 结构)。

<consistsOf>
 <content>
  <name>Rice</name>
  <price>22</price>
 </content>
 <content>
  <name>chicken</name>
  <price>44</price>
 </content>
</consistsOf>

我正在尝试使用以下代码将数据放入对象中:

XStream xstream = new XStream();
            xstream.alias("consistsOf", ContentsList.class);
            xstream.alias("content", Contents.class);
            xstream.addImplicitCollection(ContentsList.class, "consistsOf");   

我得到这个错误:

隐式集合没有“consistsOf”字段

请帮忙!

【问题讨论】:

  • 但是我不明白当我在根节点中有多个内容时如何使用此方法?我的意思是我已经尝试过类似的东西: Contents content = (Contents)xstream.fromXML(consistsOfXML);

标签: java xml-parsing xstream


【解决方案1】:

你需要

public class ContentsList {

...

    public List<Contents> consistsOf;

...

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-22
    • 2014-06-06
    • 1970-01-01
    • 2018-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多