【问题标题】:How to use parser GSON for Json,in Android Studio [duplicate]如何在Android Studio中为Json使用解析器GSON [重复]
【发布时间】:2016-09-09 14:02:23
【问题描述】:

我的 Json 数据。

{
"data":[
{
"id":"49",
"title":"Dsd",
"date":"2016-09-09 12:15:35",
"descr":"Slader",
"full_story":"Testsdsdfsdffsd",
"images":"2016-09/1472831591.jpg",
"news_read":"4049",
"rating":"150",
"genre":[
     "111",
     "222",
     "333"
]
},

我使用的 Android Studio 插件是“DTO from JSON”,这里是代码

    public class GetDataGSON {

    @SerializedName("data")
    public List<Data> data;

    public static class Data {
        @SerializedName("id")
        public String id;
        @SerializedName("title")
        public String title;
        @SerializedName("date")
        public String date;
        @SerializedName("descr")
        public String descr;
        @SerializedName("full_story")
        public String full_story;
        @SerializedName("images")
        public String images;
        @SerializedName("news_read")
        public String news_read;
        @SerializedName("rating")
        public String rating;
        @SerializedName("genre")
        public List<Genre> genre;
    }
}

由于某种原因,在这一行中我得到了错误

@SerializedName("genre")
            public List<Genre> genre;

无法解析符号“流派”

我做错了什么?

谢谢

【问题讨论】:

  • 您需要创建一个Genre 类并对类型数据进行建模
  • 我不知道 kak.Vse 自动完成。跨插件 Android 工作室“来自 JSON 的 DTO”:)
  • 这不是重复的!!! 1)我正在使用注释。 2)您链接上的人手工制作一切。不同的帖子

标签: android json android-studio gson


【解决方案1】:

根据你JSON 的说法,genre 列表中的数据只是String 的数据。所以写:

@SerializedName("genre")
public List<String> genre;

但是,如果数据比较复杂,创建模型Genre

public class Genre {
    //parameters
}

【讨论】:

  • 接受答案,如果它适合你。也许其他用户也会有同样的问题。
  • 等待 4 分钟。所以。不按按钮
猜你喜欢
  • 2013-08-26
  • 2014-05-10
  • 1970-01-01
  • 2020-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多