任何人都可以帮助我们如何使用Retrofit的回调为 json 格式创建 pojo 类。
我试过http://www.jsonschema2pojo.org/,但我觉得它没有很好地结合
感谢。
[
{
"trends": [
{
"tweet_volume": 3200,
"events": null,
"name": "#GanaPuntosSi",
"promoted_content": null,
"query": "%23GanaPuntosSi",
"url": "http://twitter.com/search/?q=%23GanaPuntosSi"
},
{
"tweet_volume": 4200,
"events": null,
"name": "#WordsThatDescribeMe",
"promoted_content": null,
"query": "%23WordsThatDescribeMe",
"url": "http://twitter.com/search/?q=%23WordsThatDescribeMe"
},
{
"tweet_volume": 1200,
"events": null,
"name": "#10PersonasQueExtra\u00f1oMucho",
"promoted_content": null,
"query": "%2310PersonasQueExtra%C3%B1oMucho",
"url": "http://twitter.com/search/?
}
}
]
答案 0 :(得分:1)
我对Json很陌生并且我对此并不了解,但重新认识它是一个关键的"" :"价值"对类型语言符号类似于python元组,或java地图,python词典......(等等)。我可以告诉您的序列化程序是非常错误的,所以提供更多详细信息,以便更有资格的人可以帮助您修复它,以便为您生成有效的JSOn。
话虽这么说,我和你一起摆弄JSON,直到它开始工作并产生了一个pojo。你可以把它粘贴到jsonschema2pojo并下载你的类..希望这有帮助:)(PS。选择Json而不是JsonSchema单选按钮)
[
{
"tweet_volume": 3200,
"events": null,
"name": "#GanaPuntosSi",
"promoted_content": null,
"query": "%23GanaPuntosSi",
"url": "http://twitter.com/search/?q=%23GanaPuntosSi"
},
{
"tweet_volume": 4200,
"events": null,
"name": "#WordsThatDescribeMe",
"promoted_content": null,
"query": "%23WordsThatDescribeMe",
"url": "http://twitter.com/search/?q=%23WordsThatDescribeMe"
},
{
"tweet_volume": 1200,
"events": null,
"name": "#10PersonasQueExtra\u00f1oMucho",
"promoted_content": null,
"query": "%2310PersonasQueExtra%C3%B1oMucho",
"url": "http://twitter.com/search/?"
}
]
答案 1 :(得分:1)
您在代码中忘记了]
。
答案 2 :(得分:0)
如果你还没有解决它,它已经很久了
-----------------------------------com.example.Example.java-----------------------------------
package com.example;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Example {
@SerializedName("trends")
@Expose
private List<Trend> trends = null;
public List<Trend> getTrends() {
return trends;
}
public void setTrends(List<Trend> trends) {
this.trends = trends;
}
}
-----------------------------------com.example.Trend.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Trend {
@SerializedName("tweet_volume")
@Expose
private Integer tweetVolume;
@SerializedName("events")
@Expose
private Object events;
@SerializedName("name")
@Expose
private String name;
@SerializedName("promoted_content")
@Expose
private Object promotedContent;
@SerializedName("query")
@Expose
private String query;
@SerializedName("url")
@Expose
private String url;
public Integer getTweetVolume() {
return tweetVolume;
}
public void setTweetVolume(Integer tweetVolume) {
this.tweetVolume = tweetVolume;
}
public Object getEvents() {
return events;
}
public void setEvents(Object events) {
this.events = events;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Object getPromotedContent() {
return promotedContent;
}
public void setPromotedContent(Object promotedContent) {
this.promotedContent = promotedContent;
}
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}