@RuMikuRu

Как получить доступ к owner?

Здравствуйте, не могу понять как получить доступ к owner, что бы достать информацию о пользователе репозитория.
Сам фаил:
{
  "total_count": 355265,
  "incomplete_results": false,
  "items": [
    {
      "id": 2126244,
      "node_id": "MDEwOlJlcG9zaXRvcnkyMTI2MjQ0",
      "name": "bootstrap",
      "full_name": "twbs/bootstrap",
      "private": false,
      "owner": {
        "login": "twbs",
        "id": 2918581,
        "node_id": "MDEyOk9yZ2FuaXphdGlvbjI5MTg1ODE=",
        "avatar_url": "https://avatars.githubusercontent.com/u/2918581?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/twbs",
        "html_url": "https://github.com/twbs",
        "followers_url": "https://api.github.com/users/twbs/followers",
        "following_url": "https://api.github.com/users/twbs/following{/other_user}",
        "gists_url": "https://api.github.com/users/twbs/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/twbs/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/twbs/subscriptions",
        "organizations_url": "https://api.github.com/users/twbs/orgs",
        "repos_url": "https://api.github.com/users/twbs/repos",
        "events_url": "https://api.github.com/users/twbs/events{/privacy}",
        "received_events_url": "https://api.github.com/users/twbs/received_events",
        "type": "Organization",
        "site_admin": false
      },
      "html_url": "https://github.com/twbs/bootstrap",
      "description": "The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.",
      "fork": false,

Запрос
public interface Service {
    @GET("search/repositories")
    Call<ItemResponce> getItems(
            @Query(value = "q",encoded = true) String q
    );
}

Класс Item
public class Item {
    @SerializedName("full_name")
    @Expose
    private String name;
    @SerializedName("avatar_url")
    @Expose
    private String avatarUrl;
    @SerializedName("html_url")
    @Expose
    private String html_url;
 
    public Item(String name,String avatarUrl,String html_url)
    {
        this.name = name;
        this.avatarUrl=avatarUrl;
        this.html_url=html_url;
    }
 
    public String getName()
    {
        return name;
    }
 
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getAvatarUrl()
    {
        return avatarUrl;
    }
 
    public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }
 
    public void setHtml_url(String html_url) {
        this.html_url = html_url;
    }
    public String getHtml_url()
    {
        return html_url;
    }
}

Класс ItemResponce
public class ItemResponce {
    @SerializedName("items")
    @Expose
    private List<Item> items;
 
 
    public List<Item> getItems()
    {
        return items;
    }
 
 
    public void setItems(List<Item> items){
        this.items = items;
    }
}
  • Вопрос задан
  • 108 просмотров
Решения вопроса 1
azerphoenix
@azerphoenix Куратор тега Java
Java Software Engineer
Добрый день.
Вот, гляньте на структуру pojo для вашего json
Было сгенерировано на сайте - https://www.jsonschema2pojo.org/
-----------------------------------com.example.Example.java-----------------------------------

package com.example;

import java.util.List;
import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

@Generated("jsonschema2pojo")
public class Example {

@SerializedName("total_count")
@Expose
public Long totalCount;
@SerializedName("incomplete_results")
@Expose
public Boolean incompleteResults;
@SerializedName("items")
@Expose
public List<Item> items = null;

}
-----------------------------------com.example.Item.java-----------------------------------

package com.example;

import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

@Generated("jsonschema2pojo")
public class Item {

@SerializedName("id")
@Expose
public Long id;
@SerializedName("node_id")
@Expose
public String nodeId;
@SerializedName("name")
@Expose
public String name;
@SerializedName("full_name")
@Expose
public String fullName;
@SerializedName("private")
@Expose
public Boolean _private;
@SerializedName("owner")
@Expose
public Owner owner;
@SerializedName("html_url")
@Expose
public String htmlUrl;
@SerializedName("description")
@Expose
public String description;
@SerializedName("fork")
@Expose
public Boolean fork;

}
-----------------------------------com.example.Owner.java-----------------------------------

package com.example;

import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

@Generated("jsonschema2pojo")
public class Owner {

@SerializedName("login")
@Expose
public String login;
@SerializedName("id")
@Expose
public Long id;
@SerializedName("node_id")
@Expose
public String nodeId;
@SerializedName("avatar_url")
@Expose
public String avatarUrl;
@SerializedName("gravatar_id")
@Expose
public String gravatarId;
@SerializedName("url")
@Expose
public String url;
@SerializedName("html_url")
@Expose
public String htmlUrl;
@SerializedName("followers_url")
@Expose
public String followersUrl;
@SerializedName("following_url")
@Expose
public String followingUrl;
@SerializedName("gists_url")
@Expose
public String gistsUrl;
@SerializedName("starred_url")
@Expose
public String starredUrl;
@SerializedName("subscriptions_url")
@Expose
public String subscriptionsUrl;
@SerializedName("organizations_url")
@Expose
public String organizationsUrl;
@SerializedName("repos_url")
@Expose
public String reposUrl;
@SerializedName("events_url")
@Expose
public String eventsUrl;
@SerializedName("received_events_url")
@Expose
public String receivedEventsUrl;
@SerializedName("type")
@Expose
public String type;
@SerializedName("site_admin")
@Expose
public Boolean siteAdmin;

}
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
Jacen11
@Jacen11
никак, ты не сделал класс овнер и не сделал его полем в йтем. Как ты вообще собирался получить то что не сделал?
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы