gpt4 book ai didi

android - 使用 XML 转换器改造返回 null

转载 作者:行者123 更新时间:2023-11-30 00:17:09 24 4
gpt4 key购买 nike

我第一次将 RetrofitXML Converter 一起使用,我的目标是获取项目标签内的描述字段。问题是,每次我执行它时,它都会返回 description null。

我的 XML 是:

<rss version="2.0">
<channel>
<title>Tests</title>
<description>First Description</description>
<link>http://teste.html</link>
<item>
<title>Test number 5 - 1/11/2017</title>
<description>
Description that I want to get
</description>
<link> http://test.html </link>
</item>
</channel>
</rss>

类(class) channel :

@Root(name="rss", strict=false)
public class Channel {

@Element(name = "title", required = false)
private String title;

@Element(name = "description", required = false)
private String description;

@Element(name = "link", required = false)
private String link;

private Item item;

public String getTitle() {return title;}

public void setTitle(String title) {this.title = title;}

public String getDescription() {return description;}

public void setDescription(String description) {this.description = description;}

public String getitem(){
Item item = new Item();
return item.getDescription();
}

public void setLink(String title) {this.link = link;}

public String getLink(String title) { return link;}
}

类(class)项目:

@Root(name="item", strict=false)
public class Item {

@Element(name = "title")
private String title;

@Element(name = "description")
private String description;

public String getTitle() {return this.title;}

public void setTitle(String title) {this.title = title;}

public String getDescription() {return this.description;}

public void setDescription(String description) {
this.description = description;
}
}

我尝试打印描述但结果为空的方法。

@Override
public void onResponse(Call<Channel> call, Response<Channel> response) {
if (response.isSuccessful()) {
Channel rss = response.body();
Log.d("Controller","Description----->: " + rss.getitem());
} else {
Log.d("Controller","Error----->:"+response.errorBody());
}
}

我做错了什么吗?

最佳答案

在花了一些时间解决这个问题后,我找到了解决方案。

问题是我应该在每个 Elementdeclaration 中添加 class Channel 标签 @Path(" channel ”)

例如:

@Element(name = "link", required = false)
@Path("channel")
private String link;

关于android - 使用 XML 转换器改造返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47052460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com