0
我的XML:需要適當的對象聲明爲我的XStream反序列化
<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。另外,如果我的XML有多個autocomplete_item標記集,xstream錯誤就會抱怨存在autocomplete_item的重複實例。
有什麼建議嗎?
我在這裏搜索了很多問題,但沒有任何東西似乎適用於我。
這正是我所需要的。謝謝。這讓我瘋狂。 – Jason