【问题标题】:Retrofit doesn't recognize nested json responseRetrofit 无法识别嵌套的 json 响应
【发布时间】:2015-07-14 04:37:49
【问题描述】:

我正在使用 Retrofit 来获取 json 响应。我还使用http://www.jsonschema2pojo.org/ 生成了模型类,但是它不起作用。问题是 json 响应不适合我的 java 对象。我错过了什么吗?

{
   "status":"ok",
   "status_message":"Query was successful",
   "data":{
      "movie_count":1,
      "limit":20,
      "page_number":1,
      "movies":[
         {
            "id":4281,
            "url":"https:\/\/yts.to\/movie\/the-third-man-1949",
            "imdb_code":"tt0041959",
            "title":"The Third Man",
            "title_long":"The Third Man (1949)",
            "slug":"the-third-man-1949",
            "year":1949,
            "rating":8.3,
            "runtime":93,
            "genres":[
               "Film-Noir",
               "Mystery"
            ],
            "language":"English",
            "mpa_rating":"Not Rated",
            "background_image":"https:\/\/s.ynet.io\/assets\/images\/movies\/the_third_man_1949\/background.jpg",
            "small_cover_image":"https:\/\/s.ynet.io\/assets\/images\/movies\/the_third_man_1949\/small-cover.jpg",
            "medium_cover_image":"https:\/\/s.ynet.io\/assets\/images\/movies\/the_third_man_1949\/medium-cover.jpg",
            "state":"ok",
            "date_uploaded":"2015-07-13 10:22:11",
            "date_uploaded_unix":1436739731
         },
      ]
   },
   "@meta":{
      "server_time":1436799207,
      "server_timezone":"Pacific\/Auckland",
      "api_version":2,
      "execution_time":"34.67 ms"
   }
}

【问题讨论】:

  • “我错过了什么吗?” - 除其他外,您的问题可能是缺少 Java 代码。如果我们看不到您的 Java 代码,我们将无法帮助您处理您的 Java 代码。换句话说,我们需要一个minimal, complete, and verifiable example
  • 通过jsonlint.com 运行您的 JSON,第 31 行出现解析错误。这可能是您的问题。

标签: android gson retrofit


【解决方案1】:

第 31 行有一个问题,您在第二个括号 { 之后放置了一个逗号 (,)。删除逗号,一切都很好。

【讨论】:

  • @krialix ,如果有用请点赞:)。
猜你喜欢
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多