你把模型课弄错了。在下面尝试
视频
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class Videos {
@SerializedName("items")
@Expose
private List<Item> items = null;
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
public Videos withItems(List<Item> items) {
this.items = items;
return this;
}
}
一小条
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Snippet {
@SerializedName("resourceId")
@Expose
private ResourceId resourceId;
public ResourceId getResourceId() {
return resourceId;
}
public void setResourceId(ResourceId resourceId) {
this.resourceId = resourceId;
}
public Snippet withResourceId(ResourceId resourceId) {
this.resourceId = resourceId;
return this;
}
}
资源ID
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class ResourceId {
@SerializedName("videoId")
@Expose
private String videoId;
public String getVideoId() {
return videoId;
}
public void setVideoId(String videoId) {
this.videoId = videoId;
}
public ResourceId withVideoId(String videoId) {
this.videoId = videoId;
return this;
}
}
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Item {
@SerializedName("snippet")
@Expose
private Snippet snippet;
public Snippet getSnippet() {
return snippet;
}
public void setSnippet(Snippet snippet) {
this.snippet = snippet;
}
public Item withSnippet(Snippet snippet) {
this.snippet = snippet;
return this;
}
}
现在,为了获取视频id,请在成功方法中使用以下代码
response.body().getItems().get(0).getSnippet().getResourceId().getVideoId();