【问题标题】:Creating pojo class and callback for retrofit为改造创建 pojo 类和回调
【发布时间】:2016-08-08 16:41:17
【问题描述】:

任何人都可以帮助如何使用 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/?
      }
   }
]

【问题讨论】:

    标签: java retrofit pojo


    【解决方案1】:

    您只是在代码中忘记了]

    【讨论】:

    • 您能否将答案编辑得更具体一些,例如右括号应该放在哪里?
    【解决方案2】:

    我对 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/?"
      }
    ]
    

    【讨论】:

    【解决方案3】:

    久违了,万一你还没解决呢

    -----------------------------------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;
    }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2017-10-26
      • 1970-01-01
      • 2017-12-04
      • 2019-06-09
      • 2015-09-10
      • 2018-12-08
      • 2015-12-24
      • 2015-01-11
      • 2021-06-26
      相关资源
      最近更新 更多