我的 XML:
<autocomplete>
<url_template>http://api-public.netflix.com/catalog/titles/autocomplete?{-join|&|term}</url_template>
<autocomplete_item>
<title short="Star Wars: Episode V: The Empire Strikes Back: Original Theatrical Version"></title>
</autocomplete_item>
</autocomplete>
我的对象:
public class AutoCompleteList
{
public String url_template;
public List<AutocompleteItem> autocomplete_item;
}
public class AutocompleteItem
{
public Title title;
}
public class Title
{
@XStreamAlias("short")
public String Short;
}
我的代码:
XStream xstream = new XStream();
xstream.alias("autocomplete", AutoCompleteList.class);
xstream.alias("title", Title.class);
AutoCompleteList myObj = (AutoCompleteList)xstream.fromXML(stringFromStream);
我无法从 XML 中检索“title short”值。
此外,如果我的 XML 有一组以上的 autocomplete_item 标记,xstream 会报错并抱怨 autocomplete_item 的实例重复。
有什么建议么?
我已经在这里搜索了许多问题,但似乎没有什么对我有用。