Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.google.gson.Gson;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.util.List;
- public class teste2 {
- static class _links {
- Fixtures fixtures;
- Players players;
- Self self;
- }
- public class Self {
- private String href;
- }
- static class Fixtures {
- private String href;
- }
- static class Players {
- private String href;
- }
- static class Page {
- String name;
- String code;
- String shortName;
- String squadMarketValue;
- String crestUrl;
- }
- public static void main(String[] args) throws Exception {
- String json = readUrl("http://api.football-data.org/v1/teams/66");
- Gson gson = new Gson();
- _links link = gson.fromJson(json, _links.class);
- Page page = gson.fromJson(json, Page.class);
- System.out.println(page.name);
- System.out.println(page.code);
- System.out.println(page.shortName);
- System.out.println(page.squadMarketValue);
- System.out.println(page.crestUrl);
- System.out.println(link.fixtures.href);
- }
- private static String readUrl(String urlString) throws Exception {
- BufferedReader reader = null;
- try {
- URL url = new URL(urlString);
- reader = new BufferedReader(new InputStreamReader(url.openStream()));
- StringBuffer buffer = new StringBuffer();
- int read;
- char[] chars = new char[1024];
- while ((read = reader.read(chars)) != -1) {
- buffer.append(chars, 0, read);
- }
- return buffer.toString();
- } finally {
- if (reader != null) {
- reader.close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement