Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 改型2.0的使用实践_Android_Json_Gson_Retrofit_Retrofit2 - Fatal编程技术网

Android 改型2.0的使用实践

Android 改型2.0的使用实践,android,json,gson,retrofit,retrofit2,Android,Json,Gson,Retrofit,Retrofit2,我是新使用改装。。。 我可以获取id、title和缩略图,但无法获取arraylist标记上的对象 请告诉我怎么做 这是我的json: { code: 200, result: { id: "7064", title: "my title", thumbnail: "http://myimage.com/image.jpg", tags: [ { name: "php", slug: "php" }, { name: "dependenc

我是新使用改装。。。 我可以获取
id
title
缩略图
,但无法获取arraylist
标记上的对象

请告诉我怎么做

这是我的json:

{
  code: 200,
  result: {
  id: "7064",
  title: "my title",
  thumbnail: "http://myimage.com/image.jpg",
  tags: [
  {
    name: "php",
    slug: "php"
  },
  {
   name: "dependencies manager",
   slug: "dependencies-manager"
  },
  {
   name: "dependencies",
   slug: "dependencies"
  },
  {
   name: "packagist",
   slug: "packagist"
  }
  ]
 }
}
这是我使用gson序列化的模型

public class Detail extends Observable implements Serializable {
    @SerializedName("code")
    public Integer code;
    @SerializedName("result")
    public Result result;

    public class Result implements Serializable {
        @SerializedName("id")
        public String id;
        @SerializedName("title")
        public String title;
        @SerializedName("date")
        public String date;
        @SerializedName("thumbnail")
        public String thumbnail;
        @SerializedName("tags")
        public ArrayList<Tags> tags = new ArrayList<>();
    }

    public class Tags implements Serializable {
        @SerializedName("name")
        public String name;
        @SerializedName("slug")
        public String slug;
        public String getName() {
            return name;
        }
    }
}
公共类详细信息扩展了可观察的实现可序列化{
@序列化名称(“代码”)
公共整数码;
@SerializedName(“结果”)
公共结果;
公共类结果实现了可序列化{
@序列化名称(“id”)
公共字符串id;
@序列化名称(“标题”)
公共字符串标题;
@序列化名称(“日期”)
公共字符串日期;
@序列化名称(“缩略图”)
公共字符串缩略图;
@序列化名称(“标记”)
public ArrayList tags=new ArrayList();
}
公共类标记实现可序列化{
@序列化名称(“名称”)
公共字符串名称;
@序列化名称(“slug”)
公共字符串段塞;
公共字符串getName(){
返回名称;
}
}
}
还有我的API

@GET("api/posts/detail/{id}")
    Call<Detail> getDetails (@Path("id") String id);
@GET(“api/posts/detail/{id}”)
调用getDetails(@Path(“id”)字符串id);

而不是
ArrayList
使用
List
,不要初始化它。所以这将是这样的

@SerializedName("tags")
List<Tags> tags; 
@SerializedName(“标记”)
列出标签;

我看不出有任何错误,您会遇到什么错误?顺便说一句,请注意json中的错误`title:“my title”“,`我没有遇到错误,但在android studio arraylist上编写代码时,“tags”在建议中不明显..我更正->title:“my title”。。。我并没有收到错误,但在android studio arraylist上编写代码时,建议中并没有显示“标记”。。。Boukharist让您使用Restrofit2.0来处理json结构相同的项目mine@AhmadEfendi为什么要为您的Details类扩展Observable?