Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. import com.google.gson.Gson;
  2. import java.io.BufferedReader;
  3. import java.io.InputStreamReader;
  4. import java.net.URL;
  5. import java.util.List;
  6.  
  7. public class teste2 {
  8.  
  9. static class _links {
  10. Fixtures fixtures;
  11. Players players;
  12. Self self;
  13.  
  14. }
  15.  
  16. public class Self {
  17. private String href;
  18. }
  19.  
  20. static class Fixtures {
  21. private String href;
  22. }
  23.  
  24. static class Players {
  25. private String href;
  26. }
  27.  
  28. static class Page {
  29. String name;
  30. String code;
  31. String shortName;
  32. String squadMarketValue;
  33. String crestUrl;
  34. }
  35.  
  36. public static void main(String[] args) throws Exception {
  37.  
  38. String json = readUrl("http://api.football-data.org/v1/teams/66");
  39.  
  40. Gson gson = new Gson();
  41. _links link = gson.fromJson(json, _links.class);
  42. Page page = gson.fromJson(json, Page.class);
  43.  
  44. System.out.println(page.name);
  45. System.out.println(page.code);
  46. System.out.println(page.shortName);
  47. System.out.println(page.squadMarketValue);
  48. System.out.println(page.crestUrl);
  49. System.out.println(link.fixtures.href);
  50. }
  51.  
  52. private static String readUrl(String urlString) throws Exception {
  53. BufferedReader reader = null;
  54. try {
  55. URL url = new URL(urlString);
  56. reader = new BufferedReader(new InputStreamReader(url.openStream()));
  57. StringBuffer buffer = new StringBuffer();
  58. int read;
  59. char[] chars = new char[1024];
  60. while ((read = reader.read(chars)) != -1) {
  61. buffer.append(chars, 0, read);
  62. }
  63. return buffer.toString();
  64. } finally {
  65. if (reader != null) {
  66. reader.close();
  67. }
  68. }
  69. }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement