Android 使用改进解析RSS
开发android应用程序并尝试解析新闻RSS提要,但该应用程序一直失败。当xml以Android 使用改进解析RSS,android,xml,rss,retrofit,retrofit2,Android,Xml,Rss,Retrofit,Retrofit2,开发android应用程序并尝试解析新闻RSS提要,但该应用程序一直失败。当xml以提要开始时,我可以解析RSS,但当xml看起来像这样时。我可以通过项目列表跟踪通道类中的问题,如果我添加required=false,则应用程序不会崩溃。这些是我用来解析RSS的类 @Root(name = "rss") public class Feed implements Serializable{ @Element(name = "channel") private Channel mChannel;
提要开始时,我可以解析RSS,但当xml看起来像这样时。我可以通过项目列表跟踪通道类中的问题,如果我添加required=false,则应用程序不会崩溃。这些是我用来解析RSS的类
@Root(name = "rss")
public class Feed implements Serializable{
@Element(name = "channel")
private Channel mChannel;
public Channel getmChannel() {
return mChannel;
}
public Feed() {
}
public Feed(Channel mChannel) {
this.mChannel = mChannel;
}
@Override
public String toString() {
return "Feed{" +
"mChannel=" + mChannel +
'}';
}
}
频道类别
@Root(name = "channel", strict = false)
public class Channel implements Serializable{
@ElementList(inline = true, name = "item")
public List<Item> items;
public Channel() {
}
public Channel(List<Item> items) {
this.items = items;
}
public List<Item> getItems() {
return items;
}
@Override
public String toString() {
return "Channel{" +
"items=" + items +
'}';
}
问题已修复,忘记在提要类中添加strict=false
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
//converter XML
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
FeedGitXivAPI feedGitXiv = retrofit.create(FeedGitXivAPI.class);
Call<Channel> call = feedGitXiv.getGitXiv();
onFailure: Unable to retrieve RSS: org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=true, name=item, required=true, type=void) on field 'items' public java.util.List com.example.anton.techy.AiMl.Channel.items for class com.example.anton.techy.AiMl.Channel at line -1