gpt4 book ai didi

java - 使用改造将 json 解析为 POJO

转载 作者:行者123 更新时间:2023-11-30 10:48:22 27 4
gpt4 key购买 nike

我正在尝试使用改造将 json 解析为 POJO,但一直出现错误。它似乎获取了数据,据我从 logcat 中看到的,我正确地读取和解析了 json。但它返回 succes=false 并且不返回 responsedata 对象。错误类型和错误消息显示为空。我不知道哪里出了问题,如果有任何解决方案或如何定位错误的建议,我将不胜感激。

JSON

{
"competition_info": {
"headline": "competition",
"description": "description for competition.",
"accept_button": "OK",
"open_terms_button": "Open info"
},
"terms": {
"html": "a website in html"
}
}

MyPojo

public class AnnComResponses{
@SerializedName("competition_info")
public CompetitionInfo competitionInfo;
@SerializedName("terms")
public Terms terms;

public class Terms{

@SerializedName("html")
public String html;

public String getTerms() {
return html;
}
}

public class CompetitionInfo{
@SerializedName("headline")
public String headline;
@SerializedName("description")
public String description;
@SerializedName("accept_button")
public String acceptButton;
@SerializedName("open_terms_button")
public String openTermsButton;

public String getHeadline() {
return headline;
}

public String getDescription() {
return description;
}

public String getAcceptButton() {
return acceptButton;
}

public String getOpenTermsButton() {
return openTermsButton;
}

}
}

最佳答案

尝试使用 GSON 转换器进行改造,如下所示:

RestAdapter restAdapter = new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.FULL)
.setConverter(new GsonConverter(new GsonBuilder()).create()))
.setEndpoint("your api end point goes here")
.build();
YourAPI api = restAdapter.create(YourAPI.class);

关于java - 使用改造将 json 解析为 POJO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35830936/

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